New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

arida

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arida - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

25

package.json
{
"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"
}
}

62

src/api.js
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);
}
})()
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc