Skip to content

Commit

Permalink
build new version
Browse files Browse the repository at this point in the history
  • Loading branch information
imtaotao committed Nov 12, 2019
1 parent 8006b1f commit bda023e
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 53 deletions.
44 changes: 31 additions & 13 deletions demo/store/mpstore.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ function restore(obj, patchs) {
return obj;
}

function applyPatchs(component, patchs) {
function applyPatchs(component, patchs, callback) {
var destObject = {};

for (var i = 0, len = patchs.length; i < len; i++) {
Expand All @@ -402,14 +402,30 @@ function applyPatchs(component, patchs) {
destObject[path] = value;
}

component.setData(destObject);
component.setData(destObject, callback);
}
function updateComponents(store) {
function updateComponents(store, callback) {
var total = 0;
var hooks = store.hooks,
GLOBALWORD = store.GLOBALWORD,
depComponents = store.depComponents;
var len = depComponents.length;
if (len === 0) return;

if (len === 0) {
if (typeof callback === 'function') {
callback();
}

return;
}

var renderedCallback = function renderedCallback() {
if (++total === len) {
if (typeof callback === 'function') {
callback();
}
}
};

for (var i = 0; i < len; i++) {
var _depComponents$i = depComponents[i],
Expand All @@ -424,6 +440,7 @@ function updateComponents(store) {

if (typeof willUpdate === 'function') {
if (willUpdate.call(store, component, newPartialState) === false) {
renderedCallback();
continue;
}
}
Expand All @@ -434,10 +451,11 @@ function updateComponents(store) {
var params = [component, newPartialState, patchs, isPage];

if (callHook(hooks, 'willUpdate', params) === false) {
renderedCallback();
continue;
}

applyPatchs(component, patchs);
applyPatchs(component, patchs, renderedCallback);

if (typeof didUpdate === 'function') {
didUpdate.call(store, component, newPartialState, patchs);
Expand All @@ -448,7 +466,11 @@ function updateComponents(store) {
if (component.timeTravel) {
component.timeTravel.push(patchs);
}
} else {
renderedCallback();
}
} else {
renderedCallback();
}
}
}
Expand Down Expand Up @@ -685,7 +707,7 @@ function () {
this.depComponents = [];
this.GLOBALWORD = 'global';
this.isDispatching = false;
this.version = '0.0.9';
this.version = '0.0.10';
this.state = Object.freeze({});
this.middleware = new Middleware(this);
}
Expand Down Expand Up @@ -734,11 +756,7 @@ function () {
restoreProcessState();
}

updateComponents(_this);

if (typeof callback === 'function') {
callback();
}
updateComponents(_this, callback);
});
}
}, {
Expand Down Expand Up @@ -823,7 +841,7 @@ function () {
var patchs = diff(component.data[GLOBALWORD], createState(), GLOBALWORD);

if (patchs.length > 0) {
applyPatchs(component, patchs);
applyPatchs(component, patchs, GLOBALWORD);
}
}
}
Expand Down Expand Up @@ -862,7 +880,7 @@ function () {
return Store;
}();

var version = '0.0.9';
var version = '0.0.10';
var nativePage = Page;
var nativeComponent = Component;

Expand Down
44 changes: 31 additions & 13 deletions dist/mpstore.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ function restore(obj, patchs) {
return obj;
}

function applyPatchs(component, patchs) {
function applyPatchs(component, patchs, callback) {
var destObject = {};

for (var i = 0, len = patchs.length; i < len; i++) {
Expand All @@ -406,14 +406,30 @@ function applyPatchs(component, patchs) {
destObject[path] = value;
}

component.setData(destObject);
component.setData(destObject, callback);
}
function updateComponents(store) {
function updateComponents(store, callback) {
var total = 0;
var hooks = store.hooks,
GLOBALWORD = store.GLOBALWORD,
depComponents = store.depComponents;
var len = depComponents.length;
if (len === 0) return;

if (len === 0) {
if (typeof callback === 'function') {
callback();
}

return;
}

var renderedCallback = function renderedCallback() {
if (++total === len) {
if (typeof callback === 'function') {
callback();
}
}
};

for (var i = 0; i < len; i++) {
var _depComponents$i = depComponents[i],
Expand All @@ -428,6 +444,7 @@ function updateComponents(store) {

if (typeof willUpdate === 'function') {
if (willUpdate.call(store, component, newPartialState) === false) {
renderedCallback();
continue;
}
}
Expand All @@ -438,10 +455,11 @@ function updateComponents(store) {
var params = [component, newPartialState, patchs, isPage];

if (callHook(hooks, 'willUpdate', params) === false) {
renderedCallback();
continue;
}

applyPatchs(component, patchs);
applyPatchs(component, patchs, renderedCallback);

if (typeof didUpdate === 'function') {
didUpdate.call(store, component, newPartialState, patchs);
Expand All @@ -452,7 +470,11 @@ function updateComponents(store) {
if (component.timeTravel) {
component.timeTravel.push(patchs);
}
} else {
renderedCallback();
}
} else {
renderedCallback();
}
}
}
Expand Down Expand Up @@ -689,7 +711,7 @@ function () {
this.depComponents = [];
this.GLOBALWORD = 'global';
this.isDispatching = false;
this.version = '0.0.9';
this.version = '0.0.10';
this.state = Object.freeze({});
this.middleware = new Middleware(this);
}
Expand Down Expand Up @@ -738,11 +760,7 @@ function () {
restoreProcessState();
}

updateComponents(_this);

if (typeof callback === 'function') {
callback();
}
updateComponents(_this, callback);
});
}
}, {
Expand Down Expand Up @@ -827,7 +845,7 @@ function () {
var patchs = diff(component.data[GLOBALWORD], createState(), GLOBALWORD);

if (patchs.length > 0) {
applyPatchs(component, patchs);
applyPatchs(component, patchs, GLOBALWORD);
}
}
}
Expand Down Expand Up @@ -866,7 +884,7 @@ function () {
return Store;
}();

var version = '0.0.9';
var version = '0.0.10';
var nativePage = Page;
var nativeComponent = Component;

Expand Down
40 changes: 28 additions & 12 deletions dist/mpstore.es6m.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,22 +257,35 @@ function restore (obj, patchs) {
return obj
}

function applyPatchs (component, patchs) {
function applyPatchs (component, patchs, callback) {
const destObject = {};
for (let i = 0, len = patchs.length; i < len; i++) {
const { value, path } = patchs[i];
destObject[path] = value;
}
component.setData(destObject);
component.setData(destObject, callback);
}
function updateComponents (store) {
function updateComponents (store, callback) {
let total = 0;
const {
hooks,
GLOBALWORD,
depComponents,
} = store;
const len = depComponents.length;
if (len === 0) return
if (len === 0) {
if (typeof callback === 'function') {
callback();
}
return
}
const renderedCallback = () => {
if (++total === len) {
if (typeof callback === 'function') {
callback();
}
}
};
for (let i = 0; i < len; i++) {
const {
isPage,
Expand All @@ -285,24 +298,30 @@ function updateComponents (store) {
const newPartialState = createState();
if (typeof willUpdate === 'function') {
if (willUpdate.call(store, component, newPartialState) === false) {
renderedCallback();
continue
}
}
const patchs = diff(component.data[GLOBALWORD], newPartialState, GLOBALWORD);
if (patchs.length > 0) {
const params = [component, newPartialState, patchs, isPage];
if (callHook(hooks, 'willUpdate', params) === false) {
renderedCallback();
continue
}
applyPatchs(component, patchs);
applyPatchs(component, patchs, renderedCallback);
if (typeof didUpdate === 'function') {
didUpdate.call(store, component, newPartialState, patchs);
}
callHook(hooks, 'didUpdate', [component, newPartialState, isPage]);
if (component.timeTravel) {
component.timeTravel.push(patchs);
}
} else {
renderedCallback();
}
} else {
renderedCallback();
}
}
}
Expand Down Expand Up @@ -504,7 +523,7 @@ class Store {
this.depComponents = [];
this.GLOBALWORD = 'global';
this.isDispatching = false;
this.version = '0.0.9';
this.version = '0.0.10';
this.state = Object.freeze({});
this.middleware = new Middleware(this);
}
Expand Down Expand Up @@ -548,10 +567,7 @@ class Store {
this.isDispatching = false;
restoreProcessState();
}
updateComponents(this);
if (typeof callback === 'function') {
callback();
}
updateComponents(this, callback);
});
}
use (action, fn) {
Expand Down Expand Up @@ -623,7 +639,7 @@ class Store {
});
const patchs = diff(component.data[GLOBALWORD], createState(), GLOBALWORD);
if (patchs.length > 0) {
applyPatchs(component, patchs);
applyPatchs(component, patchs, GLOBALWORD);
}
}
}
Expand Down Expand Up @@ -665,7 +681,7 @@ class Store {
}
}

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

0 comments on commit bda023e

Please sign in to comment.