-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
256 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { ActionsUnion, IGatsbyState, TransactionActionsUnion } from "../types" | ||
|
||
function getInitialState(): IGatsbyState["nodesStaging"] { | ||
return { nodes: new Map(), transactions: new Map() } | ||
} | ||
|
||
function addActionToTransaction( | ||
state: IGatsbyState["nodesStaging"], | ||
action: TransactionActionsUnion | ||
): void { | ||
if (!action.transactionId) { | ||
return | ||
} | ||
|
||
const transaction = state.transactions.get(action.transactionId) | ||
if (!transaction) { | ||
state.transactions.set(action.transactionId, [action]) | ||
} else { | ||
transaction.push(action) | ||
} | ||
} | ||
|
||
export const nodesStagingReducer = ( | ||
state: IGatsbyState["nodesStaging"] = getInitialState(), | ||
action: ActionsUnion | ||
): IGatsbyState["nodesStaging"] => { | ||
switch (action.type) { | ||
case `DELETE_CACHE`: | ||
return getInitialState() | ||
|
||
case `CREATE_NODE_STAGING`: { | ||
if (action.transactionId) { | ||
// state.nodes.set(action.payload.id, action.payload) | ||
addActionToTransaction(state, action) | ||
} | ||
|
||
return state | ||
} | ||
|
||
case `DELETE_NODE_STAGING`: { | ||
if (action.payload && action.transactionId) { | ||
// state.nodes.delete(action.payload.id) | ||
addActionToTransaction(state, action) | ||
} | ||
return state | ||
} | ||
case `COMMIT_STAGING_NODES`: { | ||
state.transactions.delete(action.payload.transactionId) | ||
return state | ||
} | ||
|
||
default: | ||
return state | ||
} | ||
} |
Oops, something went wrong.