0.2.3 • Published 9 years ago

datacast v0.2.3

Weekly downloads
6
License
MIT
Repository
github
Last release
9 years ago

Datacast.js

npm install datacast --save

中文

This is a data layer framework, works like jQuery custom events. One side to obtain data by registering a receiver ( receive method) The other side send data to a corresponding receiver by send methods.

Send method by a path string to determine which receiver needs to be triggered.

Path string can have a hierarchy. For example grandfather.father.children, through . to split. (it also can be a array,For example['grandfather','farther','children']

For the receiver, the child can receive the data from parent. For sending method, the parent can send data to all children.

E.g:

receive('test',data=>{
    console.log('1:',data);
});

receive('test.2',data=>{
    console.log('2:',data);
});

receive('test.2.3',data=>{
    console.log('3:',data);
});

send('test','a');
send('test.2','b');
send('test.2.3','c');

/*
* output:
 1: a
 2: a
 3: a
 2: b
 3: b
 3: c
* */

###API

/**
* register a data receiver
* @ param {string|Array} path        receive data from which path .can be a string or array (the string through the '. 'to split level)
* @ param {function} receiver        Receives the data after the execution of the callback function, the callback function accepts two parameters (data: data, path: the path string)
* @ return {function}                returns the receiver
*/
function receive(path, receiver)
/**
* register a data receiver, which will be triggered  only once
* @ param {string|Array} path            receive data from which path .can be a string or array (the string through the '. 'to split level)
* @ param {function} receiver            Receives the data after the execution of the callback function, the callback function accepts two parameters (data: data, path: the path string)
* @ return {function}                    returns the receiver
 */
function receiveOnce(path, receiver)
/**
 * cancellation data receiver
 * @param {string|Array} path            cancel which path,And its children.can be a string or array(the string through the '. 'to split level)
 * @return {undefined}
 */
function cancel(path)
/**
 * Send the message to the specified path
 * @param {string|Array} path     Send data to which path.
 * @param data                    Data
 * @return {undefined}
 */
function send(path, data)
0.3.0

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

10 years ago

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago