Skip to content

Commit

Permalink
Make alt FSA compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Oct 21, 2015
1 parent 75b9c28 commit f4818db
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
7 changes: 1 addition & 6 deletions src/alt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ class Alt {
return utils.dispatch(id, action, data, this)
}

return this.dispatcher.dispatch({
id,
action,
data,
details,
})
return this.dispatcher.dispatch(utils.fsa(id, action, data, details))
})
}

Expand Down
24 changes: 18 additions & 6 deletions src/alt/utils/AltUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ export function dispatchIdentity(x, ...a) {
this.dispatch(a.length ? [x].concat(a) : x)
}

export function fsa(id, type, payload, details) {
return {
type,
payload,
meta: {
dispatchId: id,
...details,
},

id,
action: type,
data: payload,
details,
}
}

export function dispatch(id, actionObj, payload, alt) {
const data = actionObj.dispatch(payload)
if (data === undefined) return null
Expand All @@ -59,12 +75,8 @@ export function dispatch(id, actionObj, payload, alt) {

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

return alt.dispatcher.dispatch({
id,
action: type,
data,
details,
})
// XXX standardize this
return alt.dispatcher.dispatch(fsa(id, type, data, details))
}

/* istanbul ignore next */
Expand Down
15 changes: 15 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,21 @@ const tests = {
const store = alt.createStore(Store)
alt.dispatch(action)
},

'is fsa'(done) {
alt.dispatcher.register((x) => {
assert.isDefined(x.type, 'there is a type')
assert.isDefined(x.payload, 'there is a payload')
assert.isDefined(x.meta, 'meta exists')
assert.isString(x.meta.dispatchId, 'meta contains a unique dispatch id')

assert(x.payload === 'Jane', 'the payload is correct')

done()
})

myActions.updateName('Jane')
},
}

export default tests

0 comments on commit f4818db

Please sign in to comment.