flatiron / resourceful

an isomorphic Resource engine for JavaScript

Home Page:http://github.com/flatiron/resourceful

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create new property type "fn"

Marak opened this issue · comments

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

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.

invalid