First, thanks to @Epsil0neR and @gor181 for answers but is possible than I don´t do question correctly.
Actually I ask again on Ramda Github issue because I need implement the API with curry functions.
Finally, many hours late I go`it .
Here is the code, maybe is useful for somebody: https://github.com/ramda/ramda/issues/1291
//return 'fn' with all 'obj' props
function functionize(obj, fn)
{
let fn = fn;
for( let i in obj ){ fn[i] = obj[i] };
return fn;
}
SubStore = function(options) {
this.options = options;
}
SubStore.prototype.getOptions = function() { return this.options }
SubStore.prototype.setOptions = function(options) { this.options = options }
SubStore.prototype.insert = function(doc) { return doc }
SubStore.prototype.find = function(selector, options) { return selector }
SubStore.create = function(options) {
let sub = functionize(new SubStore(options), R.curry(function (args, fn) {
let self = sub; //reference to new SubStore obj
return self[fn](args);
}))
return sub;
}
Store = function(options) {
this.options = options;
}
Store.prototype.insert = function(args) {
for (let i = 0, len = args.length; i < len; i++) {
if ( R.is(Function, args[i]) ) { args[i] = args[i]('insert') }
console.log(args[i]);
}
}
Store.prototype.find = function(args) {
for (let i = 0, len = args.length; i < len; i++) {
if ( R.is(Function, args[i]) ) { args[i] = args[i]('find') }
console.log(args[i]);
}
}
Test code
store = new Store();
sub1 = SubStore.create({path:'perfil'});
sub2 = SubStore.create({path:'rol'});
// test#1
store.insert([ sub1({name: "Foo"}), sub2({age: 18}) ]);
// test#2
store.insert([ sub1.insert({name: "Foo"}), sub2.insert({age: 18}) ]);
Is you need a Javascript ES5version just replace let with var and you must add Ramda library too for curry function.
Thanks