Skip to content

Commit f4818db

Browse files
committed
Make alt FSA compliant
1 parent 75b9c28 commit f4818db

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/alt/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ class Alt {
3131
return utils.dispatch(id, action, data, this)
3232
}
3333

34-
return this.dispatcher.dispatch({
35-
id,
36-
action,
37-
data,
38-
details,
39-
})
34+
return this.dispatcher.dispatch(utils.fsa(id, action, data, details))
4035
})
4136
}
4237

src/alt/utils/AltUtils.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ export function dispatchIdentity(x, ...a) {
4646
this.dispatch(a.length ? [x].concat(a) : x)
4747
}
4848

49+
export function fsa(id, type, payload, details) {
50+
return {
51+
type,
52+
payload,
53+
meta: {
54+
dispatchId: id,
55+
...details,
56+
},
57+
58+
id,
59+
action: type,
60+
data: payload,
61+
details,
62+
}
63+
}
64+
4965
export function dispatch(id, actionObj, payload, alt) {
5066
const data = actionObj.dispatch(payload)
5167
if (data === undefined) return null
@@ -59,12 +75,8 @@ export function dispatch(id, actionObj, payload, alt) {
5975

6076
if (fn.isFunction(data)) return data(dispatchLater, alt)
6177

62-
return alt.dispatcher.dispatch({
63-
id,
64-
action: type,
65-
data,
66-
details,
67-
})
78+
// XXX standardize this
79+
return alt.dispatcher.dispatch(fsa(id, type, data, details))
6880
}
6981

7082
/* istanbul ignore next */

test/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,21 @@ const tests = {
14821482
const store = alt.createStore(Store)
14831483
alt.dispatch(action)
14841484
},
1485+
1486+
'is fsa'(done) {
1487+
alt.dispatcher.register((x) => {
1488+
assert.isDefined(x.type, 'there is a type')
1489+
assert.isDefined(x.payload, 'there is a payload')
1490+
assert.isDefined(x.meta, 'meta exists')
1491+
assert.isString(x.meta.dispatchId, 'meta contains a unique dispatch id')
1492+
1493+
assert(x.payload === 'Jane', 'the payload is correct')
1494+
1495+
done()
1496+
})
1497+
1498+
myActions.updateName('Jane')
1499+
},
14851500
}
14861501

14871502
export default tests

0 commit comments

Comments
 (0)