-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove mutation tracking from the store
- Loading branch information
Showing
8 changed files
with
60 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,38 @@ | ||
import { | ||
ApolloAction, | ||
isMutationInitAction, | ||
isMutationResultAction, | ||
isMutationErrorAction, | ||
isStoreResetAction, | ||
} from '../actions'; | ||
export class MutationStore { | ||
private store: {[mutationId: string]: MutationStoreValue} = {}; | ||
|
||
import { | ||
SelectionSetNode, | ||
} from 'graphql'; | ||
|
||
export interface MutationStore { | ||
[mutationId: string]: MutationStoreValue; | ||
} | ||
|
||
export interface MutationStoreValue { | ||
mutationString: string; | ||
variables: Object; | ||
loading: boolean; | ||
error: Error | null; | ||
} | ||
|
||
export interface SelectionSetWithRoot { | ||
id: string; | ||
typeName: string; | ||
selectionSet: SelectionSetNode; | ||
} | ||
|
||
export function mutations( | ||
previousState: MutationStore = {}, | ||
action: ApolloAction, | ||
): MutationStore { | ||
if (isMutationInitAction(action)) { | ||
const newState = { ...previousState } as MutationStore; | ||
public get(mutationId: string): MutationStoreValue { | ||
return this.store[mutationId]; | ||
} | ||
|
||
newState[action.mutationId] = { | ||
mutationString: action.mutationString, | ||
variables: action.variables, | ||
public initMutation(mutationId: string, mutationString: string, variables: Object | undefined) { | ||
this.store[mutationId] = { | ||
mutationString: mutationString, | ||
variables: variables || {}, | ||
loading: true, | ||
error: null, | ||
}; | ||
} | ||
|
||
return newState; | ||
} else if (isMutationResultAction(action)) { | ||
const newState = { ...previousState } as MutationStore; | ||
|
||
newState[action.mutationId] = { | ||
...previousState[action.mutationId], | ||
loading: false, | ||
error: null, | ||
} as MutationStoreValue; | ||
public markMutationError(mutationId: string, error: Error) { | ||
this.store[mutationId].loading = false; | ||
this.store[mutationId].error = error; | ||
} | ||
|
||
return newState; | ||
} else if (isMutationErrorAction(action)) { | ||
const newState = { ...previousState } as MutationStore; | ||
public markMutationResult(mutationId: string) { | ||
this.store[mutationId].loading = false; | ||
this.store[mutationId].error = null; | ||
} | ||
|
||
newState[action.mutationId] = { | ||
...previousState[action.mutationId], | ||
loading: false, | ||
error: action.error, | ||
} as MutationStoreValue; | ||
} else if (isStoreResetAction(action)) { | ||
// if we are resetting the store, we no longer need information about the mutations | ||
// that are currently in the store so we can just throw them all away. | ||
return {}; | ||
public reset() { | ||
this.store = {}; | ||
} | ||
} | ||
|
||
return previousState; | ||
export interface MutationStoreValue { | ||
mutationString: string; | ||
variables: Object; | ||
loading: boolean; | ||
error: Error | null; | ||
} | ||
|
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