How to use the serializr.serializable 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 / Item.ts View on Github external
import {observable} from 'mobx';
import {identifier, reference, serializable} from 'serializr';
import {v4 as uuid} from 'uuid';
import {StaticState} from '../StaticState';
import {HeirloomType, ItemInfo, ItemType} from './ItemInfo';
import {IStatsSource, Stats} from './Stats';
import {cmp} from '../../lib/Helpers';

export type ItemId = string;

export class Item implements IStatsSource {
  @serializable(identifier()) id: ItemId = uuid();
  @serializable @observable level: number = 1;

  @serializable(reference(ItemInfo, StaticState.lookup((i) => i.items)))
  info: ItemInfo;

  get name () { return this.info.name; }
  statsSourceName: string = 'Item';

  get statsScale () {
    const maxItemLevel = StaticState.instance.getUpgradeEffects(['blacksmith']).level;
    return 1 + ((this.level - 1) / maxItemLevel);
  }

  get stats () {
    const scaledStats = new Stats();
    scaledStats.add(this.info.stats);
github ksandin / darkestdungeon / src / state / types / Profile.ts View on Github external
@observable
  estateEvent = nullEstateEvent;

  @serializable(list(object(Hero)))
  @observable
  coach: Hero[] = [];

  @serializable(list(object(Hero)))
  @observable
  roster: Hero[] = [];

  @serializable(list(object(Hero)))
  @observable
  graveyard: Hero[] = [];

  @serializable(list(object(Quest)))
  @observable
  quests: Quest[] = [];

  @serializable(list(object(Item)))
  @observable
  items: Item[] = [];

  @serializable(list(object(Dungeon)))
  @observable
  allDungeons: Dungeon[] = [];

  @serializable(list(reference(BuildingUpgradeInfo, StaticState.lookup((i) => i.buildingUpgrades))))
  @observable
  buildingUpgrades: BuildingUpgradeInfo[] = [];

  @computed get selectableDungeons () {
github ksandin / darkestdungeon / src / state / types / DungeonInfo.ts View on Github external
import {identifier, serializable} from 'serializr';
import {CharacterTemplate} from './CharacterTemplate';

export class DungeonInfo {
  @serializable(identifier()) id: string;
  name: string;
  monsters: CharacterTemplate[] = [];
  imageUrl: string;
  entranceImageUrl: string;
  roomImageUrls: string[] = [];
  isStartingDungeon: boolean;
}