How to use the relay-runtime.commitLocalUpdate function in relay-runtime

To help you get started, we’ve selected a few relay-runtime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github renanmav / relay-twitter / src / relay / Environment.tsx View on Github external
// @ts-ignore
      .subscribe(({ data }) => observer.onNext({ data }))
  );
};

const network = Network.create(fetchQuery, setupSubscription);

const source = new RecordSource();
const store = new Store(source);

const env = new Environment({
  network,
  store
});

commitLocalUpdate(env, proxyStore => {
  const fieldKey = "settings";
  const __typename = "Settings";

  const dataID = `client:${__typename}`;
  const record = proxyStore.create(dataID, __typename);

  record.setValue("light", "theme");

  // avoid garbage collection
  env.retain({
    dataID,
    variables: {},
    // @ts-ignore
    node: { selections: [] }
  });
github coralproject / talk / src / core / client / stream / local / initLocalState.ts View on Github external
export default async function initLocalState(
  environment: Environment,
  context: CoralContext
) {
  const config = await getExternalConfig(context.pym);
  await initLocalBaseState(
    environment,
    context,
    config ? config.accessToken : undefined
  );

  commitLocalUpdate(environment, s => {
    const root = s.getRoot();
    const localRecord = root.getLinkedRecord("local")!;

    // Parse query params
    const query = parseQuery(location.search);

    if (query.storyID) {
      localRecord.setValue(query.storyID, "storyID");
    }

    if (query.storyURL) {
      localRecord.setValue(query.storyURL, "storyURL");
    }

    if (query.commentID) {
      localRecord.setValue(query.commentID, "commentID");
github renanmav / relayable / packages / web / src / relay / Environment.ts View on Github external
installRelayDevTools()
}

const network = Network.create(
  process.env.NODE_ENV === 'development' ? RelayNetworkLogger.wrapFetch(cacheHandler) : cacheHandler
)

const source = new RecordSource()
const store = new Store(source)

const env = new Environment({
  network,
  store,
})

commitLocalUpdate(env, proxyStore => {
  const fieldKey = 'settings'
  const __typename = 'Settings'

  const dataID = `client:${__typename}`
  const record = proxyStore.create(dataID, __typename)

  const darkTheme = localStorage.getItem(yottaDarkTheme) === 'true'

  record.setValue(darkTheme, 'darkTheme')

  env.retain({
    dataID,
    variables: {},
    // @ts-ignore
    node: { selections: [] },
  })
github coralproject / talk / src / core / client / framework / testHelpers / createRelayEnvironment.ts View on Github external
network = Network.create(
      wrapFetchWithLogger(createFetch({ schema }), {
        logResult: params.network.logNetwork,
        muteErrors: params.network.muteNetworkErrors,
      }),
      params.network.subscriptionHandler
        ? (createSubscribe(params.network.subscriptionHandler) as any)
        : undefined
    );
  }
  const environment = new Environment({
    network,
    store: new Store(params.source || new RecordSource()),
  });
  if (params.initLocalState !== false) {
    commitLocalUpdate(environment, sourceProxy => {
      const root = sourceProxy.getRoot();
      const localRecord = createAndRetain(
        environment,
        sourceProxy,
        LOCAL_ID,
        LOCAL_TYPE
      );
      root.setLinkedRecord(localRecord, "local");
      if (typeof params.initLocalState === "function") {
        params.initLocalState(localRecord, sourceProxy, environment);
      }
    });
  }
  return environment;
}
github coralproject / talk / src / core / client / stream / common / UserBox / SetAuthPopupStateMutation.ts View on Github external
export async function commit(
  environment: Environment,
  input: SetAuthPopupStateInput
) {
  return commitLocalUpdate(environment, store => {
    const record = store.get(AUTH_POPUP_ID)!;
    if (input.open !== undefined) {
      record.setValue(input.open, "open");
    }
    if (input.focus !== undefined) {
      record.setValue(input.focus, "focus");
    }
    if (input.href !== undefined) {
      record.setValue(input.href, "href");
    }
  });
}
github coralproject / talk / src / core / client / stream / tabs / Comments / Stream / StoryClosedTimeout / SetStoryClosedMutation.ts View on Github external
export async function commit(
  environment: Environment,
  input: SetStoryClosedInput
) {
  return commitLocalUpdate(environment, store => {
    const record = store.get(input.storyID)!;
    record.setValue(input.isClosed, "isClosed");
  });
}
github coralproject / talk / src / core / client / stream / App / SetActiveTabMutation.ts View on Github external
export async function commit(
  environment: Environment,
  input: SetActiveTabInput,
  { eventEmitter }: Pick
) {
  return commitLocalUpdate(environment, store => {
    const record = store.get(LOCAL_ID)!;
    if (record.getValue("activeTab") !== input.tab) {
      SetMainTabEvent.emit(eventEmitter, { tab: input.tab });
      record.setValue(input.tab, "activeTab");
    }
  });
}
github este / este / components / core / withStore.js View on Github external
store = (storeUpdater: StoreUpdater) => {
      commitLocalUpdate(this.props.environment, storeUpdater);
    };
github coralproject / talk / src / core / client / admin / mutations / SetRedirectPathMutation.ts View on Github external
async (
    environment: Environment,
    input: SetRedirectPathInput,
    { localStorage }: CoralContext
  ) => {
    if (!input.path) {
      await localStorage.removeItem(REDIRECT_PATH_KEY);
    } else {
      await localStorage.setItem(REDIRECT_PATH_KEY, input.path);
    }

    return commitLocalUpdate(environment, store => {
      const record = store.get(LOCAL_ID)!;
      record.setValue(input.path, "redirectPath");
    });
  }
);
github coralproject / talk / src / core / client / framework / lib / relay / useLocal.tsx View on Github external
(update: LocalUpdater) => {
      commitLocalUpdate(relayEnvironment, store => {
        const record = store.get(LOCAL_ID)!;
        if (isAdvancedUpdater(update)) {
          update(record);
        } else {
          applySimplified(record, fragment.selections[0].selections, update);
        }
      });
      return;
    },
    [relayEnvironment, fragment]