dmodel icon indicating copy to clipboard operation
dmodel copied to clipboard

extenstions/jsonSchema - consider returning just the schema

Open neonstalwart opened this issue 11 years ago • 0 comments

it's hard to use extensions/jsonSchema with a custom base Model. e.g. i have a base Model for all my models which is something like this:

define(function (require) {
    var Model = require('dmodel/Model');

    return Model.createSubclass({
        rpc: function (method) {
            var params = Array.prototype.slice.call(arguments, 1);

            return this._store._rpc(this._store.target + this._store.getIdentity(this), method, params);
        }
    });
});

then each of my models just depend on that module and define their own schemas.

BaseModel.createSubcalss({
  schema: ...
});

trying to use extensions/jsonSchema causes a lot of friction because it takes a schema and returns a Model. i would have to do something like using AMD map config to map my own model as dmodel/Model into dmodel/extensions/jsonSchema or use model.prototype.schema as the schema to pass to another Model.

it would be easier if the extension took a json-schema and returned the dmodel schema so that it is used like so:

Model.createSubclass({
  schema: jsonSchema(...)
});

neonstalwart avatar Dec 08 '14 18:12 neonstalwart