Skip to content

Commit

Permalink
fix: fix update bug
Browse files Browse the repository at this point in the history
  • Loading branch information
imtaotao committed Dec 22, 2019
1 parent a92587e commit a984d8b
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 161 deletions.
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

56 changes: 30 additions & 26 deletions demo/store/mpstore.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Mpstore.js v0.1.13
* Mpstore.js v0.1.14
* (c) 2019-2019 Imtaotao
* Released under the MIT License.
*/
Expand Down Expand Up @@ -538,24 +538,27 @@ function updateComponents(store, callback) {
return;
}

var simulateDeps = depComponents.slice();
var len = simulateDeps.length;

var renderedCallback = function renderedCallback() {
if (++total === depComponents.length) {
if (++total === len) {
if (!callback._called) {
callback._called = true;
callback();
}
}
};

for (var i = 0; i < depComponents.length; i++) {
var _depComponents$i = depComponents[i],
isPage = _depComponents$i.isPage,
component = _depComponents$i.component,
didUpdate = _depComponents$i.didUpdate,
willUpdate = _depComponents$i.willUpdate,
createState = _depComponents$i.createState;
for (var i = 0; i < len; i++) {
var _simulateDeps$i = simulateDeps[i],
isPage = _simulateDeps$i.isPage,
component = _simulateDeps$i.component,
didUpdate = _simulateDeps$i.didUpdate,
willUpdate = _simulateDeps$i.willUpdate,
createState = _simulateDeps$i.createState;

if (component.data[GLOBALWORD]) {
if (component._$loaded && component.data[GLOBALWORD]) {
var newPartialState = createState();

if (typeof willUpdate === 'function') {
Expand Down Expand Up @@ -849,7 +852,7 @@ function () {
this.depComponents = [];
this.GLOBALWORD = 'global';
this.isDispatching = false;
this.version = '0.1.13';
this.version = '0.1.14';
this.state = Object.freeze(createModule({}));
this.middleware = new Middleware(this);
}
Expand Down Expand Up @@ -1080,14 +1083,20 @@ function () {
}
};

function onLoad() {
addDep(this);
this.store = store;
this._$loaded = true;
}

function onUnload() {
this._$loaded = false;
remove(store.depComponents, this);
}

if (isPage) {
config.onLoad = createWraper(config.onLoad, function () {
addDep(this);
this.store = store;
});
config.onUnload = createWraper(config.onUnload, null, function () {
remove(store.depComponents, this);
});
config.onLoad = createWraper(config.onLoad, onLoad, null);
config.onUnload = createWraper(config.onUnload, null, onUnload);
} else {
config.lifetimes = config.lifetimes || {};

Expand All @@ -1099,21 +1108,16 @@ function () {
return config[name] = config.lifetimes[name] = fn;
};

set('attached', createWraper(get('attached'), function () {
addDep(this);
this.store = store;
}));
set('detached', createWraper(get('detached'), null, function () {
remove(store.depComponents, this);
}));
set('attached', createWraper(get('attached'), onLoad, null));
set('detached', createWraper(get('detached'), null, onUnload));
}
}
}]);

return Store;
}();

var version = '0.1.13';
var version = '0.1.14';
var nativePage = Page;
var nativeComponent = Component;

Expand Down
56 changes: 30 additions & 26 deletions dist/mpstore.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Mpstore.js v0.1.13
* Mpstore.js v0.1.14
* (c) 2019-2019 Imtaotao
* Released under the MIT License.
*/
Expand Down Expand Up @@ -542,24 +542,27 @@ function updateComponents(store, callback) {
return;
}

var simulateDeps = depComponents.slice();
var len = simulateDeps.length;

var renderedCallback = function renderedCallback() {
if (++total === depComponents.length) {
if (++total === len) {
if (!callback._called) {
callback._called = true;
callback();
}
}
};

for (var i = 0; i < depComponents.length; i++) {
var _depComponents$i = depComponents[i],
isPage = _depComponents$i.isPage,
component = _depComponents$i.component,
didUpdate = _depComponents$i.didUpdate,
willUpdate = _depComponents$i.willUpdate,
createState = _depComponents$i.createState;
for (var i = 0; i < len; i++) {
var _simulateDeps$i = simulateDeps[i],
isPage = _simulateDeps$i.isPage,
component = _simulateDeps$i.component,
didUpdate = _simulateDeps$i.didUpdate,
willUpdate = _simulateDeps$i.willUpdate,
createState = _simulateDeps$i.createState;

if (component.data[GLOBALWORD]) {
if (component._$loaded && component.data[GLOBALWORD]) {
var newPartialState = createState();

if (typeof willUpdate === 'function') {
Expand Down Expand Up @@ -853,7 +856,7 @@ function () {
this.depComponents = [];
this.GLOBALWORD = 'global';
this.isDispatching = false;
this.version = '0.1.13';
this.version = '0.1.14';
this.state = Object.freeze(createModule({}));
this.middleware = new Middleware(this);
}
Expand Down Expand Up @@ -1084,14 +1087,20 @@ function () {
}
};

function onLoad() {
addDep(this);
this.store = store;
this._$loaded = true;
}

function onUnload() {
this._$loaded = false;
remove(store.depComponents, this);
}

if (isPage) {
config.onLoad = createWraper(config.onLoad, function () {
addDep(this);
this.store = store;
});
config.onUnload = createWraper(config.onUnload, null, function () {
remove(store.depComponents, this);
});
config.onLoad = createWraper(config.onLoad, onLoad, null);
config.onUnload = createWraper(config.onUnload, null, onUnload);
} else {
config.lifetimes = config.lifetimes || {};

Expand All @@ -1103,21 +1112,16 @@ function () {
return config[name] = config.lifetimes[name] = fn;
};

set('attached', createWraper(get('attached'), function () {
addDep(this);
this.store = store;
}));
set('detached', createWraper(get('detached'), null, function () {
remove(store.depComponents, this);
}));
set('attached', createWraper(get('attached'), onLoad, null));
set('detached', createWraper(get('detached'), null, onUnload));
}
}
}]);

return Store;
}();

var version = '0.1.13';
var version = '0.1.14';
var nativePage = Page;
var nativeComponent = Component;

Expand Down
57 changes: 22 additions & 35 deletions dist/mpstore.es6m.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Mpstore.js v0.1.13
* Mpstore.js v0.1.14
* (c) 2019-2019 Imtaotao
* Released under the MIT License.
*/
Expand Down Expand Up @@ -399,23 +399,25 @@ function updateComponents (store, callback) {
callback();
return
}
const simulateDeps = depComponents.slice();
const len = simulateDeps.length;
const renderedCallback = () => {
if (++total === depComponents.length) {
if (++total === len) {
if (!callback._called) {
callback._called = true;
callback();
}
}
};
for (let i = 0; i < depComponents.length; i++) {
for (let i = 0; i < len; i++) {
const {
isPage,
component,
didUpdate,
willUpdate,
createState,
} = depComponents[i];
if (component.data[GLOBALWORD]) {
} = simulateDeps[i];
if (component._$loaded && component.data[GLOBALWORD]) {
const newPartialState = createState();
if (typeof willUpdate === 'function') {
if (willUpdate.call(store, component, newPartialState) === false) {
Expand Down Expand Up @@ -669,7 +671,7 @@ class Store {
this.depComponents = [];
this.GLOBALWORD = 'global';
this.isDispatching = false;
this.version = '0.1.13';
this.version = '0.1.14';
this.state = Object.freeze(createModule({}));
this.middleware = new Middleware(this);
}
Expand Down Expand Up @@ -873,44 +875,29 @@ class Store {
}
}
};
function onLoad () {
addDep(this);
this.store = store;
this._$loaded = true;
}
function onUnload () {
this._$loaded = false;
remove(store.depComponents, this);
}
if (isPage) {
config.onLoad = createWraper(
config.onLoad,
function () {
addDep(this);
this.store = store;
},
);
config.onUnload = createWraper(
config.onUnload,
null,
function () {
remove(store.depComponents, this);
},
);
config.onLoad = createWraper(config.onLoad, onLoad, null);
config.onUnload = createWraper(config.onUnload, null, onUnload);
} else {
config.lifetimes = config.lifetimes || {};
const get = name => config[name] || config.lifetimes[name];
const set = (name, fn) => config[name] = config.lifetimes[name] = fn;
set('attached', createWraper(
get('attached'),
function () {
addDep(this);
this.store = store;
},
));
set('detached', createWraper(
get('detached'),
null,
function () {
remove(store.depComponents, this);
},
));
set('attached', createWraper(get('attached'), onLoad, null));
set('detached', createWraper(get('detached'), null, onUnload));
}
}
}

const version = '0.1.13';
const version = '0.1.14';
const nativePage = Page;
const nativeComponent = Component;
function expandConfig (config, expandMethods, isPage) {
Expand Down
Loading

0 comments on commit a984d8b

Please sign in to comment.