Create new property type "fn"
Marak opened this issue · comments
Marak commented
There should be a new type of property that can be set on resources called "fn".
This property would act as a helper method for adding what we currently call "remote" methods to resources.
Ex:
var Author = resourceful.define('author');
Author.string('name', { default: "bobby", required: true });
Author.method('hello', function(){
return 'hello';
}, optionalSchema);
Would be equivalent to the old api of:
var Author = resourceful.define('author');
Author.string('name', { default: "bobby", required: true });
Author.hello = function () {
return 'hello';
};
Author.remote = true;
This is beneficial for a few reasons:
- more declarative control over specifying non-core arbitrary functions
- as per #115, resource types can be introspected, and a function would be a type
- ability to enforce JSON-schema on function's arguments in any interface
- ability to introspect method signatures ( via schema ) generating documentation
Marak commented
The delta to add this feature is small, I've got a branch working locally now.
Polishing off the API and examples, will push the new branch in a few days.
Marak commented
Example usage https://gist.github.com/1598f9392360f9139770
Marak commented
invalid