mirror of
https://github.com/wassname/talk.git
synced 2026-09-11 12:51:33 +08:00
Updated tests and latest changes
This commit is contained in:
@@ -1,24 +1,30 @@
|
||||
import { Environment } from "relay-runtime";
|
||||
|
||||
import { LOCAL_ID } from "talk-framework/lib/relay/withLocalStateContainer";
|
||||
import { TalkContext } from "talk-framework/lib/bootstrap";
|
||||
import { createMutationContainer } from "talk-framework/lib/relay";
|
||||
import { signOff, SignOffInput } from "talk-framework/rest";
|
||||
import { SignOffInput } from "talk-framework/rest";
|
||||
import { commitLocalUpdate, Environment } from "relay-runtime";
|
||||
|
||||
export type SignOffMutation = (input: SignOffInput) => Promise<void>;
|
||||
|
||||
export async function commit(
|
||||
environment: Environment,
|
||||
input: SignOffInput,
|
||||
{ rest, localStorage }: TalkContext
|
||||
{ localStorage }: TalkContext
|
||||
) {
|
||||
try {
|
||||
await signOff(rest, input);
|
||||
return commitLocalUpdate(environment, store => {
|
||||
const record = store.get(LOCAL_ID)!;
|
||||
record.setValue("", "authToken");
|
||||
localStorage.removeItem("authToken");
|
||||
} catch (error) {
|
||||
localStorage.removeItem("authToken");
|
||||
// tslint:disable-next-line:no-console
|
||||
console.error("error", error);
|
||||
}
|
||||
|
||||
// Force gc to trigger.
|
||||
environment
|
||||
.retain({
|
||||
dataID: "tmp",
|
||||
node: { selections: [] },
|
||||
variables: {},
|
||||
})
|
||||
.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
export const withSignOffMutation = createMutationContainer("signOff", commit);
|
||||
|
||||
Reference in New Issue
Block a user