How to use the @dbeining/react-atom.addChangeHandler 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 / createGlobalState.ts View on Github external
},
    errorComponents: {},
    registry: {
      extensions: {},
      pages: {},
    },
    routes: {},
    data: {},
    portals: {},
    modules: [],
  };

  const globalState = Atom.of(extend(defaultState, customState));

  if (process.env.NODE_ENV === 'development' || process.env.DEBUG_PILET !== undefined) {
    addChangeHandler(globalState, 'debugging', ({ current, previous }) => {
      const action = new Error().stack.split('\n')[6].replace(/^\s+at\s+Atom\./, '');
      console.group(
        `%c Piral State Change %c ${new Date().toLocaleTimeString()}`,
        'color: gray; font-weight: lighter;',
        'color: black; font-weight: bold;',
      );
      console.log('%c Previous', `color: #9E9E9E; font-weight: bold`, previous);
      console.log('%c Action', `color: #03A9F4; font-weight: bold`, action);
      console.log('%c Next', `color: #4CAF50; font-weight: bold`, current);
      console.groupEnd();
    });
  }

  return globalState;
}
github smapiot / piral / packages / piral-core / src / state / createGlobalState.ts View on Github external
feeds: {},
    forms: {},
    user: {
      current: undefined,
      features: {},
      permissions: {},
    },
    search: {
      input: '',
      loading: false,
      results: [],
    },
  });

  if (process.env.NODE_ENV !== 'production') {
    addChangeHandler(globalState, 'debugging', ({ current, previous }) => {
      const action = new Error().stack.split('\n')[6].replace(/^\s+at\s+Atom\./, '');
      console.group(
        `%c Piral State Change %c ${new Date().toLocaleTimeString()}`,
        'color: gray; font-weight: lighter;',
        'color: black; font-weight: bold;',
      );
      console.log('%c Previous', `color: #9E9E9E; font-weight: bold`, previous);
      console.log('%c Action', `color: #03A9F4; font-weight: bold`, action);
      console.log('%c Next', `color: #4CAF50; font-weight: bold`, current);
      console.groupEnd();
    });
  }

  return globalState;
}

@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