Skip to content

Commit

Permalink
Revert "feat: westore数据重置及恢复,需要在业务逻辑onLoad中手动调用reset"
Browse files Browse the repository at this point in the history
  • Loading branch information
当耐特 authored Mar 22, 2019
1 parent 3b36d73 commit 93923f7
Showing 1 changed file with 7 additions and 33 deletions.
40 changes: 7 additions & 33 deletions utils/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ const FUNCTIONTYPE = '[object Function]'

export default function create(store, option) {
let updatePath = null
if (arguments.length === 2) {
if (arguments.length === 2) {
if (!originData) {
originData = JSON.parse(JSON.stringify(store.data))
globalStore = store
store.instances = {}
store.routeStack = []
store.update = update
store.push = push
store.pull = pull
store.add = add
store.remove = remove
store.reset = reset
store._originData = JSON.stringify(store.data)
store.originData = originData = JSON.parse(store._originData)
store.originData = originData
store.env && initCloud(store.env)
extendStoreMethod(store)
}
Expand All @@ -40,32 +38,18 @@ export default function create(store, option) {
this.store = store
this._updatePath = updatePath
rewriteUpdate(this)
if (store.instances[this.route]) {
store.routeStack.push(store.instances[this.route])
}
store.instances[this.route] = []
store.instances[this.route].push(this)
onLoad && onLoad.call(this, e)
syncValues(store.data, this.data)
this.setData(this.data)
}

// 解决执行navigateBack或reLaunch时清除store.instances对应页面的实例
const onUnload = option.onUnload
// 解决执行navigateBack或reLaunch时清除store.instances对应页面的实例
const onUnload = option.onUnload
option.onUnload = function () {
onUnload && onUnload.call(this)
const routeIntances = store.routeStack.pop()
store.instances[this.route] = routeIntances || []
}

const onShow = option.onShow
option.onShow = function () {
onShow && onShow.call(this)
if (!this.firstShow) {
this.firstShow = true;
return;
}
syncValues(this.data, store.data) // 恢复store数据
store.instances[this.route] = []
}

Page(option)
Expand Down Expand Up @@ -95,16 +79,6 @@ export default function create(store, option) {
}
}

function reset() {
if (globalStore) {
globalStore.originData = JSON.parse(globalStore._originData)
globalStore.data = globalStore.originData
Object.keys(fnMapping).forEach(key => {
setProp(key, fnMapping[key])
})
}
}

function syncValues(from, to){
Object.keys(to).forEach(key=>{
if(from.hasOwnProperty(key)){
Expand Down

0 comments on commit 93923f7

Please sign in to comment.