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

1.0.8 • Public • Published

@ar-kit/controllers

Hoc example

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


class ExampleController extends Controller<ExampleData> {
  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 } = '@ar-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 @ar-kit/controllers

Weekly Downloads

1

Version

1.0.8

License

MIT

Unpacked Size

38.2 kB

Total Files

20

Last publish

Collaborators

  • nicolas.garfinkiel