Skip to content

Commit 8e3c5e8

Browse files
committed
[update] Version to 3.3.0
1 parent dd601e5 commit 8e3c5e8

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
### 3.3.0
4+
5+
- `mapBy` internal function now accepts an initial value
6+
- Changed `Microcosm::dispatch` copy strategy. Instead of merging a
7+
change set, it now directly modifies a clone of the previous
8+
state.
9+
- Added `Microcosm::clone`. This method defines how state is copied
10+
before dispatching an action.
11+
312
### 3.2.0
413

514
- Changed default shouldUpdate algorithm

dist/Microcosm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/Microcosm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "microcosm",
3-
"version": "3.2.0",
3+
"version": "3.3.0",
44
"description": "A functional flux architecture",
55
"main": "dist/Microcosm.js",
66
"scripts": {

src/Microcosm.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,23 @@ export default class Microcosm {
8080
return this.dispatch(fn, request)
8181
}
8282

83+
clone() {
84+
return Object.create(this._state)
85+
}
86+
8387
dispatch(action, body) {
88+
let clone = this.clone()
89+
8490
// First get all stores that can repond to this action
8591
const answerable = this._stores.filter(store => action in store)
8692

8793
// Next build the change set
88-
const changes = mapBy(answerable, store => store[action](this.get(store), body))
94+
let next = mapBy(answerable,
95+
store => store[action](clone[store], body),
96+
clone)
8997

9098
// Produce the next state by merging changes into the current state
91-
this.swap(changes)
99+
this.reset(next)
92100

93101
// Send back the body to the original signaler
94102
return body

src/mapBy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* Take a list and reduce it into an object
44
*/
55

6-
export default function mapBy (array, fn) {
6+
export default function mapBy (array, fn, initial={}) {
77
return array.reduce(function(memo, next) {
88
memo[next] = fn(next)
99
return memo
10-
}, {})
10+
}, initial)
1111
}

0 commit comments

Comments
 (0)