Skip to content

Commit

Permalink
bump 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
benjycui committed Oct 17, 2017
1 parent f495068 commit 69bfa33
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1,785 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dva-model-extend",
"version": "0.1.1",
"version": "0.1.2",
"description": "Utility method to extend dva model.",
"main": "lib/index.js",
"files": [
Expand Down
42 changes: 24 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
const check = (origin, cache, count) => {
for (let key in origin) {
if (cache.indexOf(key) === -1) {
cache.push(key);
} else {
count[key] ? count[key]++ : count[key] = 1;
if (process.env.NODE_ENV !== 'production') {
for (let key in origin) {
if (cache.indexOf(key) === -1) {
cache.push(key);
} else {
count[key] ? count[key]++ : count[key] = 1;
}
}
}
}

const log = (model, constitute, count) => {
let logCount = 0;
for (let key in count) {
if (!logCount) {
console.warn(`Please note that some of the attributes are inherited in the ${model.namespace} / ${constitute}:`);
if (process.env.NODE_ENV !== 'production') {
let logCount = 0;
for (let key in count) {
if (!logCount) {
console.warn(`Please note that some of the attributes are inherited in the ${model.namespace} / ${constitute}:`);
}
logCount++;
console.warn(` -> ${key} be overwritten ${count[key]} time(s).`);
}
logCount++;
console.warn(`-> ${key} be overwritten ${count[key]} time(s).`);
}
}

export default function modelExtend(...models) {
const
base = { state: {}, subscriptions: {}, effects: {}, reducers: {}, },
stateCache = [], stateCount = {},
subscriptionsCache = [], subscriptionsCount = {},
effectsCache = [], effectsCount = {},
reducersCache = [], reducersCount = {};
const base = { state: {}, subscriptions: {}, effects: {}, reducers: {}, };
const stateCache = [];
const stateCount = {};
const subscriptionsCache = [];
const subscriptionsCount = {};
const effectsCache = [];
const effectsCount = {};
const reducersCache = [];
const reducersCount = {};

const model = models.reduce((acc, extend) => {

acc.namespace = extend.namespace;
if (typeof extend.state === 'object' && !Array.isArray(extend.state)) {
check(extend.state, stateCache, stateCount)
Expand Down
Loading

0 comments on commit 69bfa33

Please sign in to comment.