ra-jsdt
v0.0.1
Published
write code in nice way through ra
Downloads
1
Readme
ra
make you write code in a nice way through ra.
[email protected]
now it's just [email protected],which relies on promise or thunk .Because at the beginning, so also in the construction of perfecting
primary API
- ra.run(); //thunk function invoke
ra.run(function* () {
const msg0= yield fn('hello','world');
console.log("msg0 "+msg0); //hello world gcy //sync cb logic
});
- ra.run.toTK(); //covert normal funtion to thunk
function hw(h,w,cb) {
let hwg=h+" "+w+" "+"gcy";
cb(hwg);
}
let fn=ra.run.toTK(hw);
- ra.runPromise(); //promise invoke
let hra=ra.runPromise(function* () {
console.log("begin");
let ret=yield hwAsync('hello','world');
console.log(ret); //hello world gcy //sync cb logic
});
hra();
Installation
Direct script Include
<script src="ra/dist/index.js" />
NPM
npm install ra-jsdt
Examples
// thunk demo
function hw(h,w,cb) {
let hwg=h+" "+w+" "+"gcy";
cb(hwg);
}
let fn=ra.run.toTK(hw);
ra.run(function* () {
const msg0= yield fn('hello','world');
console.log("msg0 "+msg0); //hello world gcy //sync cb logic
});
// ---------------------------------------------------------------
// promise demo
let hwAsync= (h,w) => {
return new Promise((resolve,reject) => {
let hwg=h+" "+w+" "+"gcy";
resolve(hwg);
});}
let hra=ra.runPromise(function* () {
console.log("begin");
let ret=yield hwAsync('hello','world');
console.log(ret); //hello world gcy //sync cb logic
});
hra();
License
MIT