Newlywed Party Monsters

    flatstate

    0.1.1 • Public • Published

    flatstate

    Build Status Coverage Status donate

    A simple prototypal inheritance based state, inspired by this blog post.

    The flatstate function pollutes a generic class adding a setState method.

    Such method could also be borrowed at runtime.

    class MyEl extends HTMLElement {
      setState(state) {
        flatstate.setState.call(this, state);
        this.render(state);
      }
      render(state) {
        this.textContent = state.name;
      }
    }
    const el = new MyEl();
    el.setState({name: 'test', clicks: 0});
    el.addEventListener('click', () => {
      this.setState({
        clicks: this.state.clicks + 1
      });
    });
     
    // or alternatively
    const Class = flatstate(class {
      // prototype will have a setState method
    });

    Install

    npm i flatstate

    DownloadsWeekly Downloads

    2

    Version

    0.1.1

    License

    ISC

    Last publish

    Collaborators

    • webreflection