ian-an
v1.0.0
Published
a basic library to manage and control function
Downloads
1
Readme
Ian
a basic library to manage and control function
Ian
want to cooperates with Modules and connect them to build a extensible and readable program, like that
In order to achieve this goal, you should understand the simple principle of Ian
first.
Requiring Ian
and mount
a function
const Ian = require('ian');
const ian = new Ian();
ian.mount(fn);
It will give the fn three attributes, input
, status
and goto
After that, you can do many things with this function. for example, select the arguments, decide the next function to execute.
Ian
provides atomic api to operate function.
FUNDAMENTAL API
setFnName(FnName)
: give function a special name.createArgPool(poolName, isOnce)
: build an pool to save arguments that function can take from. WhenisOnce == true
, the pool will destory after some function take it.addArgToPool(poolName, ...value)
: add arguments to some pool. WhenpoolName == false
, those value will add to a default global arg-pool.setArgToPool(poolName, ...value)
:set arguments to some pool. WhenpoolName == false
, those value will add to a default global arg-pool.
INPUT API
lian.mount
can only recieve non-parameter function, for example, () => console.log('hello world')
. There are some other APIs that you can custom your function parameters.
acceptLast(fn)
: Whentypeof fn !== 'function'
, the results from last function will pass to this function directly. Whentypeof fn === 'function'
, the results from last function will be handled and return to this function.
lian.mount((...lastResult) => {
console.log(`There are lastResult come from last function: ${lastResult}`);
}).acceptLast();
openTo(...fnName)
: add a build-in argument to function that you can call other functions. If the argument more than one fnName or the first argument is an Array(for example,['funA', 'funB']
), all results will be return by Promise.all. IffnName[0] == false
, it will invoke next function.
lian.mount(() => console.log('I am the invoked function')).setFnName('funA');//mount a function and give a name to this function
lian.mount((to) => to()).openTo('funA');//mount a function and give a build-in argument to invoke funA
selectArgPool(...poolName)
: select arg-pools. IfpoolName[0] == false
, it will take the default global arg-pool.
lian.createArgPool('poolA').addArgToPool('poolA', 'argA', 'argB');//create an arg-pool and add two argument to it
lian.mount((argA, argB) => console.log(`I am ${argA}. I am ${argB}`)).selectArgPool('poolA');//mount a function and select poolA as arg-pool