@a-react-kit/controllers
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@a-react-kit/controllers

Hoc example

import { createStore, watcherEvent, withController, Controller } from '@a-react-kit/controllers';


class ExampleController extends Controller<ExampleData, ExampleData, ExampleEvents, any> {
  initialize = async () => {
    return { foo: 'bar' };
  };

  bootstrap = initialState => {
    const exampleEvent = (store, payload) => {
	  const anotherPayload = this.getController(AnotherController);

      return {
        ...store,
        ...payload,
        ...anotherPayload
      };
    };

    this.store = createStore(initialState);
    this.events = {
      exampleEvent: watcherEvent(exampleEvent),
    };
  };
}

export default withController([ExampleController])(DumbComponent);

Hooks

import { useStoreAndEventsOf, useStoreOf, useEventsOf } = '@a-react-kit/controllers';

function DumbComponent() {
  const [store, events] = useStoreAndEventsOf(ExampleController);
  // Or
  const store = useStoreOf(ExampleController);
  const events = useEventsOf(ExampleController);
    
  return <>
    <div>{store.foo}</div>
  	<button type="button" onClick={events.exampleEvent} />
  </>;
} 

Readme

Keywords

none

Package Sidebar

Install

npm i @a-react-kit/controllers

Weekly Downloads

2

Version

1.0.0

License

none

Unpacked Size

59.6 kB

Total Files

21

Last publish

Collaborators

  • caanvaga
  • metabaronespinosa
  • nicolas.garfinkiel