Skip to content

Commit

Permalink
Add API docs, fix global leak issue in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zemccartney committed Jun 16, 2020
1 parent 4993664 commit f5981d7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
56 changes: 56 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,59 @@ The `indexes` branch keeps a dictionary of indexes to store the status and resul
Indexing can be skipped by configuring `shouldIndex` to `false` or a function returning `true` or `false` given the index name. Indexes are initialized in the store lazily, i.e. when they are first seen on an action's `meta.index` property.

Typically `entities` and `indexes` work in tandem to keep track of normalized results from an external data-source while keeping them properly normalized.

## React Bindings

#### `<Provider middleEnd={app} />`

React Context Provider component that handles providing the passed middle-end to any nested Context consumers.


It requires the following prop:

- `middleEnd`: A composed application that is set as the context value. The app must be initialized; the component throws otherwise

```js
const StrangeMiddleEnd = require('strange-middle-end');

// const config = ... standard middle-end config e.g. input to create method

function App ({ props }) {

const m = MiddleEnd.create(config).initialize();

return (
<MiddleEnd.Provider middleEnd={m}>
{/*
Counter may now consume middleEnd context (see useMiddleEnd hook below)
*/}
<Counter />
</MiddleEnd.Provider>
)
}
```

#### `useMiddleEnd`

Hook that returns the current middle-end as contextualized by the nearest parent `Provider`.
Follows the same rendering logic as [React's built-in `useContext`](https://reactjs.org/docs/hooks-reference.html#usecontext).

```js
function Counter ({ props }) {

const m = useMiddleEnd();

return (
<div>
<button onClick={() => m.dispatch.counter.increment()}>Increment</button>
{/*
Note that this selector is NOT subscribed to our store, so will not re-render
the component on state change e.g. on clicking the button above.
For a subscribed selector, consider wrapping in react-redux's useSelector hook
e.g. useSelector(m.select.counter.get)
*/}
{m.select.counter.get()}
</div>
)
}
```
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"scripts": {
"build": "npm run clean && rollup -c",
"clean": "rimraf dist",
"test": "lab -a @hapi/code -t 100 -L",
"lint": "lab -dL",
"test": "lab -a @hapi/code -t 100 -L -I 'regeneratorRuntime'",
"lint": "lab -dL -I 'regeneratorRuntime'",
"coveralls": "lab -r lcov | coveralls"
},
"repository": {
Expand Down

0 comments on commit f5981d7

Please sign in to comment.