mirror of
https://github.com/wassname/talk.git
synced 2026-08-03 13:20:59 +08:00
No need for local state for now
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
import { Environment, RecordSource } from "relay-runtime";
|
||||
|
||||
import { LOCAL_ID } from "talk-framework/lib/relay";
|
||||
import { createRelayEnvironment } from "talk-framework/testHelpers";
|
||||
|
||||
import initLocalState from "./initLocalState";
|
||||
|
||||
let environment: Environment;
|
||||
let source: RecordSource;
|
||||
|
||||
beforeEach(() => {
|
||||
source = new RecordSource();
|
||||
environment = createRelayEnvironment({
|
||||
source,
|
||||
initLocalState: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("init local state", () => {
|
||||
initLocalState(environment);
|
||||
expect(JSON.stringify(source.toJSON(), null, 2)).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("set view from query", () => {
|
||||
const view = "MODERATE";
|
||||
const previousLocation = location.toString();
|
||||
const previousState = window.history.state;
|
||||
window.history.replaceState(
|
||||
previousState,
|
||||
document.title,
|
||||
`http://localhost/?view=${view}`
|
||||
);
|
||||
initLocalState(environment);
|
||||
expect(source.get(LOCAL_ID)!.view).toBe(view);
|
||||
window.history.replaceState(previousState, document.title, previousLocation);
|
||||
});
|
||||
@@ -1,4 +1,3 @@
|
||||
import qs from "query-string";
|
||||
import { commitLocalUpdate, Environment } from "relay-runtime";
|
||||
|
||||
import {
|
||||
@@ -17,12 +16,6 @@ export default async function initLocalState(environment: Environment) {
|
||||
// Create the Local Record which is the Root for the client states.
|
||||
const localRecord = createAndRetain(environment, s, LOCAL_ID, LOCAL_TYPE);
|
||||
|
||||
// Parse query params
|
||||
const query = qs.parse(location.search);
|
||||
|
||||
// Set default view.
|
||||
localRecord.setValue(query.view || "MODERATE", "view");
|
||||
|
||||
root.setLinkedRecord(localRecord, "local");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
enum View {
|
||||
MODERATE
|
||||
}
|
||||
|
||||
type Local {
|
||||
view: View!
|
||||
}
|
||||
type Local {}
|
||||
|
||||
extend type Query {
|
||||
local: Local!
|
||||
|
||||
Reference in New Issue
Block a user