Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master v1.0.0 #155

Merged
merged 35 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5960801
Update dependencies
richardcrng Jan 9, 2020
a884c8c
Merge pull request #151 from richardcrng/update-dependencies
richardcrng Jan 9, 2020
249957c
Pass reduxLeaves type to reducer
richardcrng Feb 6, 2020
7e6308f
Delete type specific create APIs
richardcrng Feb 6, 2020
b83994d
Rename LeafCreatorAPIUniversal to LeafCreatorAPIDefaults
richardcrng Feb 6, 2020
28c277e
Create LeafCreatorAPIDefaults inteerface
richardcrng Feb 6, 2020
dfe11fd
Type makeCreateDefaults second return value
richardcrng Feb 6, 2020
6992f0c
Type reducersDict argument to reduxLeaves
richardcrng Feb 6, 2020
d82ac59
Type standardiseReducersDict
richardcrng Feb 6, 2020
3e006b0
Create LeafCreatorAPICustoms type
richardcrng Feb 6, 2020
5d33c88
Clean up typing of reduxLeaves
richardcrng Feb 6, 2020
15434a4
Type LeafCreatorAPI
richardcrng Feb 6, 2020
bd3e745
Provide default type to LeafCreatorAPI
richardcrng Feb 6, 2020
ea2ed27
Type LeafCreate API
richardcrng Feb 6, 2020
adf691f
Create LeafReducerDict type
richardcrng Feb 6, 2020
f349b7c
Re-implement custom Dict type
richardcrng Feb 7, 2020
2842960
Type ActionsProxy
richardcrng Feb 7, 2020
27476fa
Create objectMap utility
richardcrng Feb 7, 2020
4250246
Experiment with prepareForActionsProxy
richardcrng Feb 7, 2020
f59fa97
Create recursive ProxiedActions type
richardcrng Feb 7, 2020
01b2a70
Test for specific create APIs in main integration test
richardcrng Feb 7, 2020
2a1fb7d
Provide typings for LeafCreatorAPIDefaults
richardcrng Feb 7, 2020
1ef346c
Provide typing for ProxyActions
richardcrng Feb 7, 2020
8efbdd2
Rename apply to do to avoid ts confusion
richardcrng Feb 7, 2020
c99a0b6
Bump to v1.0.0 - apply to do is breaking
richardcrng Feb 7, 2020
8c1d199
Export some helpfult ypes from index.ts
richardcrng Feb 7, 2020
27c4f30
Merge pull request #152 from richardcrng/typing-state
richardcrng Feb 7, 2020
a5cb2dc
Update site icon
richardcrng Feb 7, 2020
457fe40
Change casing of title
richardcrng Feb 7, 2020
d2a4834
Merge pull request #153 from richardcrng/favicon-change
richardcrng Feb 7, 2020
5d2553e
Link from GH main readme to docs website
richardcrng Feb 7, 2020
5881be6
Merge branch 'master' into master-v0.8.0
richardcrng Feb 7, 2020
751db4f
Fix conflict in bundle documentation
richardcrng Feb 7, 2020
e3e3ac0
Merge pull request #154 from richardcrng/gh-readme
richardcrng Feb 7, 2020
92cee65
Merge branch 'master-v0.8.0' of github.com:richardcrng/redux-leaves i…
richardcrng Feb 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# redux-leaves
# Redux Leaves

Write once. Reduce anywhere.

Expand All @@ -17,11 +17,11 @@ npm install --save redux-leaves
[Main documentation website](https://redux-leaves.js.org)

### Getting started
- [Overview](docs/intro/README.md)
- [30 second demo](docs/examples/basicExample.md)
- [Overview](https://redux-leaves.js.org/docs/intro/overview)
- [30 second demo](https://runkit.com/richardcrng/redux-leaves-playground/)

### API reference
- [Core: `reduxLeaves(initialState, reducers)`](docs/README.md)
- [Core: `reduxLeaves(initialState, reducers)`](https://redux-leaves.js.org/docs/redux-leaves)

### Testing

Expand Down
5 changes: 2 additions & 3 deletions docs/api/bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ const store = createStore(reducer)

const incrementThenPush = bundle([
actions.counter.create.increment(),
actions.list.create.apply((leafState, treeState) => [...leafState, treeState.counter])
actions.list.create.do((leafState, treeState) => [...leafState, treeState.counter])
])

const pushThenIncrement = bundle([
actions.list.create.apply((leafState, treeState) => [...leafState, treeState.counter]),
actions.counter.create.increment()
actions.list.create.do((leafState, treeState) => [...leafState, treeState.counter]), actions.counter.create.increment()
])

store.dispatch(incrementThenPush)
Expand Down
4 changes: 2 additions & 2 deletions docs/api/bundle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ describe('bundle bundles together actions into a single one', () => {
test('Processes actions in the order passed into the array', () => {
const incrementThenPush = bundle([
actions.counter.create.increment(),
actions.list.create.apply((leafState, treeState) => [...leafState, treeState.counter])
actions.list.create.do((leafState, treeState) => [...leafState, treeState.counter])
])

const pushThenIncrement = bundle([
actions.list.create.apply((leafState, treeState) => [...leafState, treeState.counter]), actions.counter.create.increment()
actions.list.create.do((leafState, treeState) => [...leafState, treeState.counter]), actions.counter.create.increment()
])

store.dispatch(incrementThenPush)
Expand Down
71 changes: 0 additions & 71 deletions docs/defaults/apply.md

This file was deleted.

41 changes: 0 additions & 41 deletions docs/defaults/apply.spec.js

This file was deleted.

71 changes: 71 additions & 0 deletions docs/defaults/do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
id: do
title: do
hide_title: true
sidebar_label: do
---

# `do(callback)`
**`create.do`**
**`create(actionType).do`**
*Appropriate leaf state: any*

Returns an (action) object that the [reduxLeaves](../README.md) reducer uses to non-mutatively update the leaf's state to the return value of `callback(leafState, treeState)`.

*Note: creating an action using `do(callback)` does not follow Redux's non-enforced recommendation that [actions should always be serializable](https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants), since the resultant action will have the function `callback` as its `payload`.*

## Parameters
- `callback` *(function)*: invoked by the leaf's reducer with two arguments, `leafState` and `entireState`

## Returns
`action` *(object)*: an object to dispatch to the `store`

## Example
```js
import { createStore } from 'redux'
import reduxLeaves from 'reduxLeaves'

const initialState = {
bool: false,
num: 2,
str: 'foo',
arr: [1, 2, 3]
}

const [reducer, actions] = reduxLeaves(initialState)
const store = createStore(reducer)
```

### Calling `create.do` on a leaf:

```js
const doToString = actions.str.create.do
store.dispatch(doToString(state => state.toUpperCase()))
console.log(store.getState().str) // 'FOO'
```

### Calling `create(actionType).do` on a leaf:

```js
const doToBoolean = actions.bool.create('APPLY_TO_BOOLEAN').do
store.dispatch(doToBoolean(state => !state))
console.log(store.getState().bool) // true
```

### Calling `create.do` on a branch:

```js
const doToState = actions.create.do
store.dispatch(doToState(state => ({ num: state.num, arr: state.arr }))
console.log(store.getState()) // { num: 2, arr: [1, 2, 3] }
```

### Calling `create.do` with two arguments:

```js
const doToArray = actions.arr.create.do
store.dispatch(doToArray(
(leafState, treeState) => leafState.map(element => element * treeState.num)
))
console.log(store.getState()) // { num: 2, arr: [2, 4, 6] }
```
41 changes: 41 additions & 0 deletions docs/defaults/do.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { createStore } from "redux";
import reduxLeaves from '../../src';

describe("leaf.create.do(callback): returns an action that, when dispatched, updates the leaf's state to the return value of callback(state, entireState)", () => {
const initialState = {
bool: false,
num: 2,
str: 'foo',
arr: [1, 2, 3],
obj: {}
}

const [reducer, actions] = reduxLeaves(initialState)
const store = createStore(reducer)

test("Calling create.do on a leaf", () => {
const doToString = actions.str.create.do
store.dispatch(doToString(state => state.toUpperCase()))
expect(store.getState().str).toBe('FOO')
})

test("Calling create(actionType).do on a leaf", () => {
const doToBoolean = actions.bool.create('APPLY_TO_BOOLEAN').do
store.dispatch(doToBoolean(state => !state))
expect(store.getState().bool).toBe(true)
})

test("Calling create.do on a branch", () => {
const doToState = actions.create.do
store.dispatch(doToState(state => ({ num: state.num, arr: state.arr })))
expect(store.getState()).toEqual({ num: 2, arr: [1, 2, 3] })
})

test("Calling create.do with two arguments", () => {
const doToArray = actions.arr.create.do
store.dispatch(doToArray(
(leafState, treeState) => leafState.map(element => element * treeState.num)
))
expect(store.getState()).toEqual({ num: 2, arr: [2, 4, 6] })
})
})