1.0.2 • Published 3 years ago

redux-jetpack v1.0.2

Weekly downloads
1,768
License
MIT
Repository
github
Last release
3 years ago

redux-jetpack

Helpers for Boilerplate-free Redux

Based on "Implementing Redux is tedious. But it doesn’t have to be."

Install

npm install redux-jetpack

Usage

Here is an example.

  /*
    This is the shape of your store's state
  */

  type State = {
    networks: { type: string; count: number }[];
    user: {
      name: string;
    };
  };

  const initialState: State = {
    networks: [
      { type: "ssb", count: 1000 },
      { type: "ipfs", count: 100 },
      { type: "dat", count: 10 }
    ],
    user: {
      name: "jeswin"
    }
  };

  /* Create the store */
  const store = jetpack.createStore(initialState);

  /* Your component */
  const MyComponent = (props: {
    id: number;
    location: string;
    name: string;
  }) => (
    <div>
      <h1>
        Hello {props.name} ({props.location}, {props.id})
      </h1>
    </div>
  );

  /* Connect the component to the store */
  const Wrapped = jetpack.connect(MyComponent, (state: State) => state.user);

  /* Wrap component in redux's Provider, you're ready to go. */
  const App = (
    <Provider store={store.reduxStore}>
      <Wrapped id={10} location="blr" />
    </Provider>
  );

  /* Enzyme test */
  const doc = mount(App) as any;
  doc
    .render()
    .find("h1")
    .should.have.text("Hello jeswin (blr, 10)");

For more examples, see the tests

1.0.2

3 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

7 years ago

0.0.1

7 years ago