Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gatsby): Convert redux/actions/add-page-dependency to TS #22062

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/gatsby/src/db/loki/nodes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const _ = require(`lodash`)
const invariant = require(`invariant`)
const { getDb, colls } = require(`./index`)
import { createPageDependency } from "../../redux/actions/add-page-dependency"

// ///////////////////////////////////////////////////////////////////
// Node collection metadata
Expand Down Expand Up @@ -168,7 +169,6 @@ function getTypes() {
function getNodeAndSavePathDependency(id, path) {
invariant(id, `id is null`)
invariant(id, `path is null`)
const createPageDependency = require(`../../redux/actions/add-page-dependency`)
const node = getNode(id)
createPageDependency({ path, nodeId: id })
return node
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/query/graphql-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "graphql"
import { debounce } from "lodash"
import nodeStore from "../db/nodes"
import createPageDependency from "../redux/actions/add-page-dependency"
import { createPageDependency } from "../redux/actions/add-page-dependency"

import withResolverContext from "../schema/context"
import { LocalNodeModel } from "../schema/node-model"
Expand Down
40 changes: 0 additions & 40 deletions packages/gatsby/src/redux/actions/add-page-dependency.js

This file was deleted.

46 changes: 46 additions & 0 deletions packages/gatsby/src/redux/actions/add-page-dependency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { store } from "../"

import { createPageDependency as internalCreatePageDependency } from "./internal"

export const createPageDependency = ({
path,
nodeId,
connection,
}: {
path: string
nodeId: string
connection: string
}): void => {
const { componentDataDependencies } = store.getState()

// Check that the dependencies aren't already recorded so we
// can avoid creating lots of very noisy actions.
let nodeDependencyExists = false
let connectionDependencyExists = false
if (!nodeId) {
nodeDependencyExists = true
}
if (
nodeId &&
componentDataDependencies.nodes.has(nodeId) &&
componentDataDependencies.nodes.get(nodeId).has(path)
) {
nodeDependencyExists = true
}
if (!connection) {
connectionDependencyExists = true
}
if (
connection &&
componentDataDependencies.connections.has(connection) &&
componentDataDependencies.connections.get(connection).has(path)
) {
connectionDependencyExists = true
}
if (nodeDependencyExists && connectionDependencyExists) {
return
}

// It's new, let's dispatch it
store.dispatch(internalCreatePageDependency({ path, nodeId, connection }))
}
MichaelDeBoey marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 0 additions & 2 deletions packages/gatsby/src/redux/actions/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
IRemoveStaleJobAction,
} from "../types"

// import type { Plugin } from "./types"

/**
* Create a dependency between a page and data. Probably for
* internal use only.
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/redux/nodes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow */

import { createPageDependency } from "./actions/add-page-dependency"
const { store } = require(`./index`)

/**
Expand Down Expand Up @@ -77,7 +78,6 @@ exports.hasNodeChanged = (id, digest) => {
* @returns {Object} node
*/
exports.getNodeAndSavePathDependency = (id, path) => {
const createPageDependency = require(`./actions/add-page-dependency`)
const node = getNode(id)
createPageDependency({ path, nodeId: id })
return node
Expand Down
5 changes: 4 additions & 1 deletion packages/gatsby/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export interface IReduxState {
nodesByType?: Map<any, any> // TODO
jobsV2: any // TODO
lastAction: ActionsUnion
componentDataDependencies: any // TODO
componentDataDependencies: {
connections: any // TODO
nodes: any // TODO
}
components: any // TODO
staticQueryComponents: any // TODO
webpackCompilationHash: any // TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { store } = require(`../../redux`)
const { actions } = require(`../../redux/actions`)

jest.mock(`../../redux/actions/add-page-dependency`)
const createPageDependency = require(`../../redux/actions/add-page-dependency`)
import { createPageDependency } from "../../redux/actions/add-page-dependency"

require(`../../db/__tests__/fixtures/ensure-loki`)()

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/schema/__tests__/build-node-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jest.mock(`../../utils/api-runner-node`)
const apiRunnerNode = require(`../../utils/api-runner-node`)

jest.mock(`../../redux/actions/add-page-dependency`)
const createPageDependency = require(`../../redux/actions/add-page-dependency`)
import { createPageDependency } from "../../redux/actions/add-page-dependency"

const { TypeConflictReporter } = require(`../infer/type-conflict-reporter`)
const typeConflictReporter = new TypeConflictReporter()
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby/src/schema/context.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createPageDependency } from "../redux/actions/add-page-dependency"

const { LocalNodeModel } = require(`./node-model`)
const { defaultFieldResolver } = require(`./resolvers`)

Expand All @@ -9,7 +11,6 @@ const withResolverContext = ({
nodeModel,
}) => {
const nodeStore = require(`../db/nodes`)
const createPageDependency = require(`../redux/actions/add-page-dependency`)

if (!nodeModel) {
nodeModel = new LocalNodeModel({
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/schema/infer/__tests__/infer-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { LocalNodeModel } = require(`../../node-model`)
const nodeStore = require(`../../../db/nodes`)
const { store } = require(`../../../redux`)
const { actions } = require(`../../../redux/actions`)
const createPageDependency = require(`../../../redux/actions/add-page-dependency`)
import { createPageDependency } from "../../../redux/actions/add-page-dependency"
require(`../../../db/__tests__/fixtures/ensure-loki`)()

jest.mock(`gatsby-cli/lib/reporter`, () => {
Expand Down