How to use the serializr.custom 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 / Path.ts View on Github external
import {custom, serializable} from 'serializr';

export type PathTypes = Path | string;

export class Path {
  public static separator: string = '/';

  @serializable public value: string;

  @serializable(custom((val) => val, (val) => val))
  public args: any;

  get parts () {
    return this.value.split(Path.separator);
  }

  get root () {
    return this.parts[0];
  }

  constructor (
    value: string = '',
    args: any = {}
  ) {
    this.value = value;
    this.args = args;
github pinqy520 / mobx-persist / lib / types.js View on Github external
function _default() {
    return serializr_1.custom(_walk, function (v) { return v; });
}
function object(s) {
github pinqy520 / mobx-persist / src / types.ts View on Github external
function _default() {
    return custom(_walk, (v: any) => v)
}
github ksandin / darkestdungeon / src / state / types / StatItem.ts View on Github external
static serializr () {
    return custom(StatItem.serialize, StatItem.deserialize);
  }
github nathanstitt / mobx-decorated-models / lib / class-decorator.js View on Github external
function getSerializer(options, defaultSerializer) {
    if (options.serializer) {
        return customSerializer(
            options.serializer[0],
            options.serializer[1],
        );
    }
    const fns = (CustomSerializerTypes[options.type] || defaultSerializer)();
    if (options.writeOnly) {
        return {
            serializer: () => SKIP,
            deserializer: fns.deserializer,
        };
    }
    return fns;
}
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 }) {