Improve relay-runtime types

This commit is contained in:
Chi Vinh Le
2018-08-30 13:57:25 +02:00
parent 8f7b983d50
commit aa81e796d4
2 changed files with 18 additions and 2 deletions

View File

@@ -60,6 +60,11 @@ export interface OperationDefaults {
response: Variables;
}
// ~~~~~~~~~~~~~~~~~~~~~
// Constants
// ~~~~~~~~~~~~~~~~~~~~~
export const ROOT_ID: string;
// ~~~~~~~~~~~~~~~~~~~~~
// RelayQL
// ~~~~~~~~~~~~~~~~~~~~~
@@ -189,7 +194,7 @@ export interface RecordProxy {
export interface RecordSourceProxy {
create(dataID: DataID, typeName: string): RecordProxy;
delete(dataID: DataID): void;
get(dataID: DataID): Array<RecordProxy | null> | null;
get(dataID: DataID): RecordProxy | null;
getRoot(): RecordProxy;
}
@@ -1010,7 +1015,7 @@ export type Observable<T> = RelayObservable<T>;
// commitLocalUpdate
// ~~~~~~~~~~~~~~~~~~~~~
// exposed through RelayModern, not Runtime directly
export type commitLocalUpdate = (environment: Environment, updater: StoreUpdater) => void;
export function commitLocalUpdate(environment: Environment, updater: StoreUpdater): void;
// ~~~~~~~~~~~~~~~~~~~~~
// commitRelayModernMutation

View File

@@ -6,6 +6,8 @@ import {
ConnectionHandler,
ViewerHandler,
RecordSourceInspector,
commitLocalUpdate,
ROOT_ID,
} from "relay-runtime";
const source = new RecordSource();
@@ -60,3 +62,12 @@ function handlerProvider(handle: any) {
// ~~~~~~~~~~~~~~~~~~~~~
const inspector = new RecordSourceInspector(source);
// ~~~~~~~~~~~~~~~~~~~~~
// commitLocalUpdate
// ~~~~~~~~~~~~~~~~~~~~~
commitLocalUpdate(environment, store => {
const root = store.get(ROOT_ID)!;
root.setValue("foo", "localKey");
});