How to use the serializr.list 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 / Battler.ts View on Github external
import {Character} from './Character';
import {Skill} from './Skill';
import {list, object, serializable} from 'serializr';
import {cmp, contains, moveItem} from '../../lib/Helpers';
import {randomizeItem} from '../../lib/Helpers';
import {CharacterStatus} from './CharacterStatus';

type AllyOrEnemy = Character;

export class Battler<
  TAlly extends AllyOrEnemy = AllyOrEnemy,
  TEnemy extends AllyOrEnemy = AllyOrEnemy
> {
  @serializable @observable turn: number = 0;
  @serializable @observable turnActorIndex: number = 0;
  @serializable(list(object(Character))) @observable enemies: TEnemy[] = [];
  @serializable(list(object(Character))) @observable deceasedEnemies: TEnemy[] = [];

  // No need to serialize since it's automated by quest behavior
  @observable public allies: TAlly[] = null;
  @observable private enemySource: TEnemy[] = null;
  @observable public inBattle: boolean = false;

  @computed get turnActorOrder (): AllyOrEnemy[] {
    return [...this.allies, ...this.enemies]
      .sort((a, b) => cmp(a.stats.speed, b.stats.speed));
  }

  @computed get turnActor () {
    return this.turnActorOrder[this.turnActorIndex];
  }
github ksandin / darkestdungeon / src / state / types / Quest.ts View on Github external
@serializable isEscapable?: boolean = true;

  @serializable(object(QuestMap))
  map: QuestMap;

  @serializable(object(QuestObjective))
  objective: QuestObjective = new QuestObjective();

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

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

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

  // Data that changes throughout a quest
  @serializable @observable status: QuestStatus = QuestStatus.Idle;
  @serializable @observable light: number = 100;
  @serializable(list(object(Item))) @observable items: Item[] = [];
  @serializable @observable previousRoomId: MapLocationId = null;
  @serializable @observable currentRoomId: MapLocationId = null;

  @computed get lightPercentage () {
    return cap(this.light / 100, 0, 1);
  }

  @computed get previousRoom () {
    return this.map.rooms.find((room) => room.id === this.previousRoomId);
github nathanstitt / mobx-decorated-models / dist / build.module.js View on Github external
hasMany: function hasMany(model) {
        return list(object(model));
    },
    belongsTo: function belongsTo(model) {
github ksandin / darkestdungeon / src / state / types / Curio.ts View on Github external
import {identifier, list, object, serializable} from 'serializr';
import {v4 as uuid} from 'uuid';
import {Item} from './Item';
import {TurnStats} from './Stats';
import {observable} from 'mobx';

export type CurioId = string;

export class Curio {
  @serializable(identifier()) id: CurioId = uuid();
  @serializable name: string = '';
  @serializable(object(TurnStats)) buff: TurnStats = null;
  @serializable(list(object(Item))) @observable items: Item[] = [];
  @serializable @observable hasBeenInteractedWith: boolean = false;
  @serializable replaceQuirk: boolean;
}
github ksandin / darkestdungeon / src / state / types / Profile.ts View on Github external
@serializable(date()) @observable dateOfLastSave: Date = new Date();
  @serializable @observable selectedQuestId?: QuestId;
  @serializable @observable gold: number = 0;
  @observable debt: number = 0;

  @computed get goldAfterDebt () { return this.gold - this.debt; }

  @serializable(object(EstateEvent))
  @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)))
github pinqy520 / mobx-persist / lib / types.js View on Github external
function list(s) {
    return serializr_1.list(object(s));
}
function map(s) {
github lennerd / git-for-beginners / src / models / TutorialState.js View on Github external
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;
  }
}

export default TutorialState;
github ksandin / darkestdungeon / src / state / types / Character.ts View on Github external
);
  }

  @computed get flaws () {
    return Object.freeze(
      this.quirks.filter((q) => !q.isDisease && q.isNegative)
    );
  }

  @computed get diseases () {
    return Object.freeze(
      this.quirks.filter((q) => q.isDisease)
    );
  }

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

  @serializable @observable hunger: number = 0;

  @serializable @observable classInfoStatsScale = 1;

  @serializable @observable buffSourceName: string;

  @serializable(object(TurnStats))
  @observable
  buff: TurnStats;

  @serializable(map(object(TurnStats)))
  @observable
  dots = new Map();
github pinqy520 / mobx-persist / src / types.ts View on Github external
function list(s: any) {
    return _list(object(s))
}