How to use the serializr.getDefaultModelSchema 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 associationSerializers(modelClass, propName, options) {
    return {
        serializer: options.serializer ||
            modelClass.serialize ||
            object(getDefaultModelSchema(modelClass)).serializer,
        deserializer: options.deserializer ||
            modelClass.deserializer ||
            (
                (attrs, context) => {
                    let model;
                    // double equals catches null/undefined
                    if (null == attrs) { attrs = {}; }
                    if (attrs instanceof modelClass) {
                        model = attrs;
                    } else {
                        model = setupModel(
                            Object.assign({}, options, { attrs, modelClass }),
                        );
                    }
                    if (options.inverseOf) {
                        markNonserializable(model, options.inverseOf);
github nathanstitt / mobx-decorated-models / lib / class-decorator.js View on Github external
}
    });

    // 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
function addReference(parentModel, propName, options, cb) {
    var model = findModel(propName, options);
    if (model) {
        getDefaultModelSchema(parentModel).props[propName] = cb(model, options);
    } else {
        PendingLookups.push({ parentModel: parentModel, propName: propName, options: options, cb: cb });
    }
}
github nathanstitt / mobx-decorated-models / dist / build.module.js View on Github external
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;

        var referencedModel = findModel(propName, options);

        if (referencedModel) {
            var parentModelSchema = getDefaultModelSchema(parentModel);
            parentModelSchema.props[propName] = cb(model, options);
            PendingLookups.splice(i, 1);
        }
    }
};
github nathanstitt / mobx-decorated-models / lib / class-decorator.js View on Github external
serialize() {
        const schema = getDefaultModelSchema(this.constructor);
        return serialize(schema, this);
    },
    update(json, callback) {
github pinqy520 / mobx-persist / lib / index.js View on Github external
return function hydrate(key, store, initialState, customArgs) {
        if (initialState === void 0) { initialState = {}; }
        if (customArgs === void 0) { customArgs = {}; }
        var schema = serializr_1.getDefaultModelSchema(store);
        function hydration() {
            var promise = storage.getItem(key)
                .then(function (d) { return !jsonify ? d : JSON.parse(d); })
                .then(mobx_1.action("[mobx-persist " + key + "] LOAD_DATA", function (persisted) {
                if (persisted && typeof persisted === 'object') {
                    serializr_1.update(schema, store, persisted, null, customArgs);
                }
                merge_x_1.mergeObservables(store, initialState);
                return store;
            }));
            promise.rehydrate = hydration;
            return promise;
        }
        var result = hydration();
        mobx_1.reaction(function () { return serializr_1.serialize(schema, store); }, function (data) { return storage.setItem(key, !jsonify ? data : JSON.stringify(data)); }, {
            delay: debounce
github nathanstitt / mobx-decorated-models / dist / build.module.js View on Github external
serialize: function serialize$$1() {
        var schema = getDefaultModelSchema(this.constructor);
        return serialize(schema, this);
    },
    update: function update$$1(json, callback) {
github nathanstitt / mobx-decorated-models / lib / class-decorator.js View on Github external
function addReference(parentModel, propName, options, cb) {
    const model = findModel(options.model, propName);
    if (model) {
        getDefaultModelSchema(parentModel).props[propName] = cb(model, propName, options);
    } else {
        getDefaultModelSchema(parentModel).props[propName] = objectSerializer();
        PendingLookups.push({
            parentModel, propName, options, cb,
        });
    }
}