mirror of
https://github.com/wassname/talk.git
synced 2026-07-17 11:33:39 +08:00
Add SetViewMutation
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { Environment, RecordSource } from "relay-runtime";
|
||||
|
||||
import { LOCAL_ID } from "talk-framework/lib/relay";
|
||||
import { createRelayEnvironment } from "talk-framework/testHelpers";
|
||||
|
||||
import { commit } from "./SetViewMutation";
|
||||
|
||||
let environment: Environment;
|
||||
const source: RecordSource = new RecordSource();
|
||||
|
||||
beforeAll(() => {
|
||||
environment = createRelayEnvironment({
|
||||
source,
|
||||
});
|
||||
});
|
||||
|
||||
it("Sets view", () => {
|
||||
const view = "SIGN_UP";
|
||||
commit(environment, { view }, {} as any);
|
||||
expect(source.get(LOCAL_ID)!.view).toEqual(view);
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { commitLocalUpdate, Environment } from "relay-runtime";
|
||||
|
||||
import { TalkContext } from "talk-framework/lib/bootstrap";
|
||||
import { createMutationContainer } from "talk-framework/lib/relay";
|
||||
import { LOCAL_ID } from "talk-framework/lib/relay/withLocalStateContainer";
|
||||
|
||||
export interface SetViewInput {
|
||||
// TODO: replace with generated typescript types.
|
||||
view: "SIGN_IN" | "SIGN_UP" | "FORGOT_PASSWORD";
|
||||
}
|
||||
|
||||
export type SetViewMutation = (input: SetViewInput) => Promise<void>;
|
||||
|
||||
export async function commit(
|
||||
environment: Environment,
|
||||
input: SetViewInput,
|
||||
{ pym }: TalkContext
|
||||
) {
|
||||
return commitLocalUpdate(environment, store => {
|
||||
const record = store.get(LOCAL_ID)!;
|
||||
record.setValue(input.view, "view");
|
||||
});
|
||||
}
|
||||
|
||||
export const withSetViewMutation = createMutationContainer("setView", commit);
|
||||
@@ -0,0 +1 @@
|
||||
export { withSetViewMutation, SetViewMutation } from "./SetViewMutation";
|
||||
Reference in New Issue
Block a user