How to use the @dbeining/react-atom.swap function in @dbeining/react-atom

To help you get started, we’ve selected a few @dbeining/react-atom 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 smapiot / piral / src / packages / piral-core / src / state / actions / data.ts View on Github external
key: string,
  value: any,
  owner: string,
  target: DataStoreTarget,
  expires: number,
) {
  const isNull = !value && typeof value === 'object';
  const data = isNull
    ? value
    : {
        value,
        owner,
        target,
        expires,
      };
  swap(ctx, state => ({
    ...state,
    data: updateKey(state.data, key, data),
  }));

  this.emit('store-data', {
    name,
    target,
    value,
    owner,
    expires,
  });
}
github smapiot / piral / src / packages / piral-modals / src / actions.ts View on Github external
export function closeModal(ctx: Atom, dialog: OpenModalDialog) {
  swap(ctx, state => ({
    ...state,
    modals: excludeItem(state.modals, dialog),
  }));
}
github smapiot / piral / src / packages / piral-translate / src / create.ts View on Github external
return context => {
    context.defineActions(createActions(localizer));

    swap(context.state, state => ({
      ...state,
      components: {
        ...state.components,
        LanguagesPicker: DefaultPicker,
      },
      language: {
        loading: false,
        available: localizer.languages,
        selected: localizer.language,
      },
    }));

    return () => {
      let localTranslations: LocalizationMessages = {};

      return {
github smapiot / piral / src / packages / piral-core / src / actions / app.ts View on Github external
export function injectPilet(ctx: Atom, pilet: Pilet) {
  swap(ctx, state => ({
    ...state,
    modules: replaceOrAddItem(state.modules, pilet, m => m.name === pilet.name),
    registry: removeNested(state.registry, m => m.pilet === pilet.name),
  }));
}
github smapiot / piral / src / packages / piral-search / src / actions.ts View on Github external
export function appendSearchResults(ctx: Atom, items: Array, done: boolean) {
  swap(ctx, state => ({
    ...state,
    search: {
      ...state.search,
      results: {
        loading: !done,
        items: appendItems(state.search.results.items, items),
      },
    },
  }));
}
github smapiot / piral / src / packages / piral-dashboard / src / actions.ts View on Github external
export function unregisterTile(ctx: Atom, name: string) {
  swap(ctx, state => ({
    ...state,
    registry: {
      ...state.registry,
      tiles: withoutKey(state.registry.tiles, name),
    },
  }));
}
github smapiot / piral / src / packages / piral-notifications / src / create.ts View on Github external
return context => {
    context.defineActions(actions);

    swap(context.state, state => ({
      ...state,
      components: {
        ...state.components,
        NotificationsHost: DefaultHost,
        NotificationsToast: DefaultToast,
      },
      notifications: getNotifications(context, messages, defaultOptions),
    }));

    return {
      showNotification(content, customOptions) {
        const notification = createNotification(context, selectId(), content, defaultOptions, customOptions);
        context.openNotification(notification);
        return notification.close;
      },
    };
github smapiot / piral / src / packages / piral-core / src / actions / app.ts View on Github external
export function setRoute(
  ctx: Atom,
  path: string,
  component: ComponentType>,
) {
  swap(ctx, state => ({
    ...state,
    routes: withKey(state.routes, path, component),
  }));
}
github smapiot / piral / src / packages / piral-core / src / actions / portal.ts View on Github external
export function destroyPortal(ctx: Atom, id: string) {
  swap(ctx, state => ({
    ...state,
    portals: withoutKey(state.portals, id),
  }));
}
github smapiot / piral / src / packages / piral-dashboard / src / actions.ts View on Github external
export function registerTile(ctx: Atom, name: string, value: TileRegistration) {
  swap(ctx, state => ({
    ...state,
    registry: {
      ...state.registry,
      tiles: withKey(state.registry.tiles, name, value),
    },
  }));
}

@dbeining/react-atom

State management made simple for React. Built on React Hooks. Inspired by `atom`s in `reagent.cljs`.

MIT
Latest version published 3 years ago

Package Health Score

48 / 100
Full package analysis