How to use the serializr.createSimpleSchema 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 lennerd / git-for-beginners / src / models / TutorialState.js View on Github external
import { serializable, list, createSimpleSchema, primitive, object, custom, SKIP } from 'serializr';
import { observable, toJS } from 'mobx';

var Action = createSimpleSchema({
  type: primitive(),
  payload: custom(
    (value) => value === undefined ? SKIP : toJS(value),
    (value) => value
  ),
});

var Milestone = createSimpleSchema({
  chapterId: primitive(),
  index: primitive(),
});

class TutorialState {
  @serializable @observable currentChapterId;
  @serializable(list(object(Action))) @observable actions = [];
  @serializable(list(object(Milestone))) @observable milestones = [];

  static create({ chapters }) {
    const state = new TutorialState();

    state.currentChapterId = chapters[0].id;

    return state;
  }
github pinqy520 / mobx-persist / lib / persist-object.js View on Github external
Object.keys(params).forEach(function (key) {
        if (typeof params[key] === 'object') {
            if (params[key].type in types_1.types) {
                if (typeof params[key].schema === 'object') {
                    schema[key] = types_1.types[params[key].type](createModel(params[key].schema));
                }
                else {
                    schema[key] = types_1.types[params[key].type](params[key].schema);
                }
            }
        }
        else if (params[key] === true) {
            schema[key] = true;
        }
    });
    return serializr_1.createSimpleSchema(schema);
}
github lennerd / git-for-beginners / src / models / TutorialState.js View on Github external
import { serializable, list, createSimpleSchema, primitive, object, custom, SKIP } from 'serializr';
import { observable, toJS } from 'mobx';

var Action = createSimpleSchema({
  type: primitive(),
  payload: custom(
    (value) => value === undefined ? SKIP : toJS(value),
    (value) => value
  ),
});

var Milestone = createSimpleSchema({
  chapterId: primitive(),
  index: primitive(),
});

class TutorialState {
  @serializable @observable currentChapterId;
  @serializable(list(object(Action))) @observable actions = [];
  @serializable(list(object(Milestone))) @observable milestones = [];