How to use the @reactorx/core.Actor.of function in @reactorx/core

To help you get started, we’ve selected a few @reactorx/core 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 querycap / reactorx / @reactorx / form / src / Actors.ts View on Github external
changed?: boolean; // value updates
  touched?: boolean; // blured
  visited?: boolean; // focused
  error?: string;
}

export interface IFormState {
  fields: Dictionary;
  initials: TFormValues;
  values: TFormValues;
  submitting?: boolean;
}

export type TFormErrors = Dictionary;

export const FormActor = Actor.of("form");

export const formKey = (formName: string) => `${FormActor.group}::${formName}`;

const formKeyFromActor = (actor: Actor) => formKey(actor.opts.form);

export const formInitial = FormActor.named("initial").effectOn(formKeyFromActor, (_, { arg }) => ({
  fields: {},
  initials: arg,
  values: cloneDeep(arg),
}));

export const formDestroy = FormActor.named("destroy").effectOn(formKeyFromActor, () => undefined);

export const formStartSubmit = FormActor.named("start-submit").effectOn(
  formKeyFromActor,
  (formState: IFormState) => ({
github querycap / reactorx / @reactorx / persister / src / PersisterActor.ts View on Github external
import { Actor, useStore } from "@reactorx/core";
import { useMemo } from "react";
import { IStoreOpts, persistedKeys } from "./Persister";

const PersisterActor = Actor.of("persister");

const persist = PersisterActor.named("register").effectOn(persistedKeys, (state, { opts }) => ({
  ...state,
  [opts.key]: opts || {},
}));

export const usePersist = (key: string, opts: Partial = {}) => {
  const store$ = useStore();

  // register persist key before all
  // ugly but have to
  useMemo(() => {
    if (!(store$.getState()[persistedKeys] || {})[key]) {
      persist
        .with(undefined, {
          ...opts,
github querycap / reactorx / @reactorx / router / src / ReactorxRouter.tsx View on Github external
import { Actor, useEpic, useStore } from "@reactorx/core";
import { History, LocationDescriptorObject, Path } from "history";
import { Observable } from "rxjs";
import { filter, ignoreElements, tap } from "rxjs/operators";
import { IRouterProps, Router } from "./Router";
import React, { useEffect, useMemo } from "react";

export const RouterActor = Actor.of("router");

export const routerActors = {
  push: RouterActor.named