You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constfs=require('fs');constobsify=require('obsify');obsify(fs.readFile)('package.json','utf8').map(data=>JSON.parse(data)).subscribe(data=>{console.log(data.name);//=> 'obsify'});// or observableify all methods in a moduleobsify(fs).readFile('package.json','utf8').map(data=>JSON.parse(data)).subscribe(data=>{console.log(data.name);//=> 'obsify'});
API
obsify(input, [options])
input
Type: function, object
Callback-style function or module whose methods you want to observableify.
options
include
Type: array of (string|regex)
Methods in a module to observableify. Remaining methods will be left untouched.
exclude
Type: array of (string|regex)
Default: [/.+Sync$/]
Methods in a module not to observableify. Methods with names ending with 'Sync' are excluded by default.
excludeMain
Type: boolean
Default: false
By default, if given module is a function itself, this function will be observableified. Turn this option on if you want to observableify only methods of the module.
constobsify=require('obsify');functionfn(){returntrue;}fn.method=(data,callback)=>{setImmediate(()=>{callback(data,null);});};// observableify methods but not fn()constobservableFn=obsify(fn,{excludeMain: true});if(observableFn()){observableFn.method('hi').subscribe(data=>{console.log(data);});}