1.0.0 • Published 8 years ago

ian-an v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

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

cooperating with module

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

function`s attributes

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. When isOnce == true, the pool will destory after some function take it.
  • addArgToPool(poolName, ...value): add arguments to some pool. When poolName == false, those value will add to a default global arg-pool.
  • setArgToPool(poolName, ...value):set arguments to some pool. When poolName == 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): When typeof fn !== 'function', the results from last function will pass to this function directly. When typeof 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. If fnName[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. If poolName[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

GOTO API