-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(okam-core): optimize ant array data operation
- Loading branch information
Showing
11 changed files
with
308 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/okam-core/src/extend/data/observable/ant/array.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* @file Array data update proxy for ant application | ||
* @author [email protected] | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/* eslint-disable fecs-export-on-declare */ | ||
|
||
const componentApi = { | ||
__spliceData(path, spliceArgs, observer) { | ||
let spliceInfo = {[path]: spliceArgs}; | ||
this.$spliceData(spliceInfo, this.__nextTickCallback); | ||
// update the cache raw data | ||
observer.rawData = observer.getContextData(); | ||
} | ||
}; | ||
|
||
const observableArray = { | ||
push(observer, rawPush, ...items) { | ||
let {ctx, selector} = observer; | ||
|
||
ctx.__spliceData(selector, [this.length, 0, ...items], observer); | ||
|
||
return rawPush.apply(this, items); | ||
}, | ||
|
||
shift(observer, rawShift) { | ||
let {ctx, selector} = observer; | ||
if (!this.length) { | ||
return rawShift.call(this); | ||
} | ||
|
||
ctx.__spliceData(selector, [0, 1], observer); | ||
|
||
return rawShift.call(this); | ||
}, | ||
|
||
unshift(observer, rawUnshift, ...items) { | ||
let {ctx, selector} = observer; | ||
ctx.__spliceData(selector, [0, 0, ...items], observer); | ||
|
||
return rawUnshift.apply(this, items); | ||
}, | ||
|
||
pop(observer, rawPop) { | ||
let {ctx, selector} = observer; | ||
let len = this.length; | ||
if (!len) { | ||
return rawPop.call(this); | ||
} | ||
ctx.__spliceData(selector, [len - 1, 1], observer); | ||
|
||
return rawPop.call(this); | ||
}, | ||
|
||
splice(observer, rawSplice, ...args) { | ||
let {ctx, selector} = observer; | ||
ctx.__spliceData(selector, args, observer); | ||
|
||
return rawSplice.apply(this, args); | ||
} | ||
}; | ||
|
||
Object.keys(observableArray).forEach(k => { | ||
let raw = observableArray[k]; | ||
observableArray[k] = function (...args) { | ||
let observer = args[0]; | ||
observer.ctx.__dataUpTaskNum++; | ||
let result = raw.apply(this, args); | ||
|
||
observer.notifyWatcher(this, this, observer.paths); | ||
|
||
return result; | ||
}; | ||
}); | ||
|
||
export { | ||
observableArray as array, | ||
componentApi as component | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.