How to use the serializr.createModelSchema function in serializr

To help you get started, we’ve selected a few serializr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nathanstitt / mobx-decorated-models / lib / class-decorator.js View on Github external
function decorateModel(model) {
    Object.assign(model.prototype, MixedInInstanceMethods);
    Object.assign(model, MixedInClassMethods);

    registerModel(model);
    const serializeSchema = {};
    const { properties } = getSchema(model);
    properties.forEach(({ type, options }, name) => {
        if (Fields[type]) {
            serializeSchema[name] = Fields[type](options, name);
        }
    });

    // eslint-disable-next-line new-cap
    createModelSchema(model, serializeSchema, ({ json }) => new model(json));

    properties.forEach(({ type, options }, name) => {
        if (Associations[type] || options.model) {
            addReference(model, name, options, Associations[type] || Associations.belongsTo);
        }
    });
    for (let i = PendingLookups.length - 1; i >= 0; i -= 1) {
        const { parentModel, propName, options, cb } = PendingLookups[i];
        const referencedModel = findModel(options.model, propName);
        if (referencedModel) {
            const parentModelSchema = getDefaultModelSchema(parentModel);
            parentModelSchema.props[propName] = cb(referencedModel, propName, options);
            PendingLookups.splice(i, 1);
        }
    }
}
github nathanstitt / mobx-decorated-models / dist / build.module.js View on Github external
var schema = getModelSchema(model);

    ModelsMap[model.name] = model;
    var serializeSchema = {};

    schema.forEach(function (_ref, name) {
        var type = _ref.type,
            options = _ref.options;

        if (SimpleHandlers[type]) {
            serializeSchema[name] = SimpleHandlers[type](options, name);
        }
    });

    createModelSchema(model, serializeSchema);

    schema.forEach(function (_ref2, name) {
        var type = _ref2.type,
            options = _ref2.options;

        if (AsyncHandlers[type]) {
            addReference(model, name, options, AsyncHandlers[type]);
        }
    });

    for (var i = PendingLookups.length - 1; i >= 0; i -= 1) {
        var _PendingLookups$i = PendingLookups[i],
            parentModel = _PendingLookups$i.parentModel,
            propName = _PendingLookups$i.propName,
            options = _PendingLookups$i.options,
            cb = _PendingLookups$i.cb;