Skip to content

Commit

Permalink
* [jsfm] fix callback
Browse files Browse the repository at this point in the history
  • Loading branch information
terrykingcha committed Apr 22, 2016
1 parent 121181b commit 2f85737
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/js-framework/lib/app/__test__/ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,20 @@ describe('the api of app', () => {
describe('callback', () => {
it('with a simple data', () => {
const data = {a: 'b'}
app.callback('1', data, false)
app.callback('1', data, true)
expect(spy2.calledOnce).to.be.true
expect(spy2.args[0][0]).to.deep.equal(data)
expect(app.callbacks[1]).to.be.a('function')
})

it('multiple called', () => {
const data = {a: 'b'}
app.callback('1', data, false)
app.callback('1', data, true)
expect(spy2.calledTwice).to.be.true
expect(spy2.args[0][0]).to.deep.equal(data)
expect(app.callbacks[1]).to.be.a('function')

app.callback('1', data, true)
app.callback('1', data, false)
expect(spy2.calledThrice).to.be.true
expect(spy2.args[0][0]).to.deep.equal(data)
expect(app.callbacks[1]).to.be.undefined
Expand Down
4 changes: 2 additions & 2 deletions src/js-framework/lib/app/ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ export function fireEvent(ref, type, e, domChanges) {
return new Error(`invalid element reference "${ref}"`)
}

export function callback(callbackId, data, ifLast) {
export function callback(callbackId, data, ifKeepAlive) {
const callback = this.callbacks[callbackId]

if (typeof callback === 'function') {
callback(data) // data is already a object, @see: lib/framework.js

if (typeof ifLast === 'undefined' || ifLast === true) {
if (typeof ifKeepAlive === 'undefined' || ifKeepAlive === false) {
this.callbacks[callbackId] = undefined
}

Expand Down

0 comments on commit 2f85737

Please sign in to comment.