Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "arida", | ||
"version": "0.0.3", | ||
"description": "一个用于数据订阅的工具库,尤其适用于扩展react,以允许子组件可以订阅父组件的数据,当父组件的数据更新时,及时更新子组件数据。", | ||
"main": "lib/index.js", | ||
"version": "0.0.4", | ||
"description": "", | ||
"main": "lib/index", | ||
"scripts": { | ||
"build": "babel src -d lib", | ||
"test": "babel-node babel test " | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/azl397985856/arida.git" | ||
}, | ||
"keywords": [ | ||
"event", | ||
"react" | ||
], | ||
"author": "Lu Zhipeng", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/azl397985856/arida/issues" | ||
}, | ||
"homepage": "https://github.com/azl397985856/arida#readme", | ||
"devDependencies": { | ||
"babel-cli": "^6.6.5", | ||
"babel-core": "^6.7.2", | ||
"babel-preset-es2015": "^6.6.0" | ||
"arida": "0.0.3" | ||
} | ||
} |
import core from './core'; | ||
let src = {}; | ||
module.exports = { | ||
subcribe(sourceName, callback) { | ||
core.listen(sourceName, callback); | ||
init(source) { | ||
src = source; | ||
return src; | ||
}, | ||
dispatch(sourceName, data) { | ||
if (this.source[sourceName] === data) { | ||
return; | ||
} else { | ||
for (let key in data) { | ||
if (Object.prototype.hasOwnProperty.call(data, key)) { | ||
if (this.source[key] == data[key]){ | ||
return; | ||
} else { | ||
console.log(this.source[key], data[key]); | ||
core.trigger(sourceName, data); | ||
} | ||
subcribe(keys, callback) { | ||
if(Object.prototype.toString.apply(keys) === '[object Array]') { | ||
keys.map((item) => { | ||
core.listen(item, callback); | ||
}); | ||
} else if(typeof keys === "string"){ | ||
core.listen(keys, callback); | ||
} else if(typeof keys === 'object'){ | ||
for (let key in keys) { | ||
if (Object.prototype.hasOwnProperty.call(keys, key)) { | ||
core.listen(key, callback); | ||
} | ||
} | ||
} else { | ||
console.error('subcribe\'s first argument must by a key, list of keys or <obje></obje>ct, please check your argument and try again!'); | ||
} | ||
}, | ||
init(source) { | ||
this.source = source; | ||
update(data) { | ||
setSource(data); | ||
}, | ||
get() { | ||
return getSource(); | ||
} | ||
} | ||
} | ||
function dispatch(data) { | ||
for (let key in data) { | ||
if (Object.prototype.hasOwnProperty.call(data, key)) { | ||
if (src[key] == data[key]){ | ||
return; | ||
} else { | ||
core.trigger(key, data); | ||
} | ||
} | ||
} | ||
}; | ||
function getSource() { | ||
return src; | ||
}; | ||
function setSource(data) { | ||
dispatch(data); | ||
for (let key in data) { | ||
if (Object.prototype.hasOwnProperty.call(data, key)) { | ||
src[key] = data[key]; | ||
} | ||
} | ||
} |
import api from './api'; | ||
module.exports.api = api; | ||
module.exports = api; |
import arida from '../src/index'; | ||
const sourceName = 'test'; | ||
const source = {a: '1', b: '2'}; | ||
let data = {a: 1}; | ||
let i = 1; | ||
const source = {id: 1, name: '2', loc: 'henan'}; | ||
let data = {id: 1, loc: 'henan'}; | ||
let i = 0; | ||
let locs = ['河南', 'beijing', 'hangzhou']; | ||
(function test() { | ||
@@ -10,10 +11,12 @@ /*arida.api.subcribe('aaa', () => { | ||
});*/ | ||
arida.api.init(source); | ||
arida.api.subcribe(sourceName, () => { | ||
// console.log('subcribe success, listen on ' + sourceName); | ||
const init = arida.init(source); | ||
arida.subcribe({loc: 'nanjing'}, () => { | ||
console.log('subcribe success, listen on ' + sourceName); | ||
}); | ||
while(i < 5) { | ||
data.a = i++; | ||
arida.api.dispatch(sourceName, data); | ||
while(i <2) { | ||
data.id = i++; | ||
// data.loc = locs[i]; | ||
arida.update(data); | ||
console.log(init); | ||
} | ||
})() |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
1
2890
5
110
2
3
2
0
1