How to use the serializr.primitive 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 ksandin / darkestdungeon / src / state / types / Character.ts View on Github external
@serializable(object(TurnStats))
  @observable
  buff: TurnStats;

  @serializable(map(object(TurnStats)))
  @observable
  dots = new Map();

  @serializable(object(Stats))
  @observable mutableStats = new Stats();

  @serializable(map(primitive()))
  @observable
  private skillLevels = new Map();

  @serializable(map(primitive()))
  @observable
  private skillSelections = new Map();

  get skills () {
    return this.classInfo.skills.map((info) => new Skill(this.skillLevels, this.skillSelections, info));
  }

  get selectedSkills () {
    return this.skills.filter((skill) => skill.isSelected);
  }

  @computed get scaledClassInfo () {
    const scaled = {...this.classInfo}; // Clone to avoid mutating static instance
    scaled.stats = new Stats();
    scaled.stats.add(this.classInfo.stats);
    scaled.stats.scale(this.classInfoStatsScale);
github mobxjs / mobx / test / base / decorate.js View on Github external
test("decorate a property with two decorators", function() {
    let updatedByAutorun

    class Obj {
        x = null
    }

    decorate(Obj, {
        x: [serializable(primitive()), observable]
    })

    const obj = deserialize(Obj, {
        x: 0
    })

    const d = autorun(() => {
        updatedByAutorun = obj.x
    })

    expect(isObservableProp(obj, "x")).toBe(true)
    expect(updatedByAutorun).toEqual(0)

    obj.x++

    expect(obj.x).toEqual(1)
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 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 = [];
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 nathanstitt / mobx-decorated-models / dist / build.module.js View on Github external
function readonlyPrimitive() {
    var defaultSerial = primitive();
    return {
        serializer: function serializer() {
            return undefined;
        },
        deserializer: defaultSerial.deserializer
    };
}
github lennerd / git-for-beginners / src / models / Action.js View on Github external
import { serializable, primitive, custom, SKIP } from "serializr";
import { action, computed } from "mobx";

class Action {
  @serializable(primitive()) type;
  @serializable(custom(
    value => value === undefined ? SKIP : value,
    json => json
  )) payload;

  constructor(type, payload) {
    this.type = type;
    this.payload = payload;
  }

  is(type) {
    return this.type === type.toString();
  }

  toString() {
    return this.type;
github nathanstitt / mobx-decorated-models / dist / build.module.js View on Github external
field: function field() {
        return primitive();
    },
    session: function session() {