Example #1
0
const getNextPrevValue = (location, geocodes) => {

  let result = new Map();
  if(location && (!geocodes || !geocodes.isEmpty())) {

    let prev;
    let cur;
    let next;
    geocodes.forEach(x => {
      if (x.name === location)
        cur = x;
      else if (cur && !next)
        next = x;
      else if (!cur)
        prev = x;
    });
    if (!next)
      next = geocodes.first();
    if (!prev)
      prev = geocodes.last();

    result = result.setIn(['prev'], new Map(prev));
    result = result.setIn(['cur'], new Map(cur));
    result = result.setIn(['next'], new Map(next));
  }
  return result;
}
Example #2
0
export default function game(state: Map = fromJS(GAME_STATE), action: Action): Map {
  switch (action.type) {
    case START_GAME: {
      const board = fromJS(action.board);
      const input = fromJS({
        values: [],
        max: 5,
      });
      return state
        .set('board', board)
        .set('score', 0)
        .set('input', input)
        .set('started', true)
        .set('paused', false)
        .set('finished', false);
    }
    case 'SET_ROWS': {
      const rows = fromJS(action.rows);
      return state.setIn(['board', 'rows'], rows);
    }
    case END_GAME: {
      return state
        .set('paused', false)
        .set('finished', true);
    }
    case ADD_ROW: {
      const row = fromJS(action.row);
      const rows = state.getIn(['board', 'rows']).push(row);

      return state.setIn(['board', 'rows'], rows);
    }
    case ADD_INPUT: {
      const { value } = action;

      const values = state.getIn(['input', 'values']).push(value);
      return state.setIn(['input', 'values'], values);
    }
    case POP_INPUT: {
      const values = state.getIn(['input', 'values']).pop();
      return state.setIn(['input', 'values'], values);
    }
    case 'CLEAR_INPUT': {
      return state.setIn(['input', 'values'], List());
    }
    case ENTER_INPUT: {
      const word = state.getIn(['input', 'values']).join('');
      return state;
    }
    default: {
      return state;
    }
  }
}
Example #3
0
test('Your rank frow when you reach class level 15', t => {
  const reqClassXp = classXpData[0] // sum required xp to reach class level 15
    .reduce((prev, curr) => prev + curr, 0);
  const state = INITIAL_STATE
    .setIn(['character', 'initial', 'classXp'], reqClassXp);
  const rank = calculatorReducer(state, { type: CALCULATE })
    .getIn(['character', 'rank']);

  t.is(rank, 2);
});
Example #4
0
  it('should not mutate the actual state object in anyway', () => {
    const state = new Map({});
    const wrappedState = wrappedStateFactory(state, { key: 'foo', strictMode: true });
    wrappedState.setIn(['man', '1'], 'dog');
    expect(console.warn.calledOnce).to.equal(true);

    expect(state.get('man', 'backup')).to.equal('backup');
    state.setIn(['man', '1'], 'dog');
    expect(console.warn.calledOnce).to.equal(true);
  });
Example #5
0
test('You can use % as initial baseXp and classXp', t => {
  const state = INITIAL_STATE
    .setIn(['character', 'initial', 'baseXp'], '50%')
    .setIn(['character', 'initial', 'classXp'], '50%');

  const character = calculatorReducer(state, { type: CALCULATE })
    .get('character');

  t.is(character.get('baseXp'), Math.floor(baseXpData[1] * 50 / 100));
  t.is(character.get('classXp'), Math.floor(classXpData[0][1] * 50 / 100));
});
Example #6
0
test('Gain XP for each card you have', t => {
  for (let i = 0; i < 12; i++) {
    const state = INITIAL_STATE.setIn(['cards', i], 1);
    const character = calculatorReducer(state, { type: CALCULATE }).get('character');

    t.is(
      character.get('accumulatedBaseXp'),
      cardsXpData[i].base
    );
  }
});
Example #7
0
 _toggleDeepChildren(id: ElementID, value: boolean) {
   var node = this._nodes.get(id);
   if (!node) {
     return;
   }
   if (node.get('collapsed') !== value) {
     this._nodes = this._nodes.setIn([id, 'collapsed'], value);
     this.emit(id);
   }
   var children = node.get('children');
   if (children && children.forEach) {
     children.forEach(cid => this._toggleDeepChildren(cid, value));
   }
 }
Example #8
0
test("Can't overflow max base level and max rank", t => {
  const absurdlyHugeAmmountOfBaseXp = baseXpData[MAX_BASE_LEVEL - 1] * 1000000;
  const absurdlyHugeAmmountOfClassXp = classXpData[MAX_RANK - 1][14] * 1000000;
  const state = INITIAL_STATE
    .setIn(['character', 'initial', 'baseLevel'], MAX_BASE_LEVEL)
    .setIn(['character', 'initial', 'classLevel'], 15)
    .setIn(['character', 'initial', 'rank'], MAX_RANK)
    .setIn(['character', 'initial', 'baseXp'], absurdlyHugeAmmountOfBaseXp)
    .setIn(['character', 'initial', 'classXp'], absurdlyHugeAmmountOfClassXp);
  const character = calculatorReducer(state, { type: CALCULATE })
    .get('character');

  t.is(character.get('baseLevel'), MAX_BASE_LEVEL);
  t.is(character.get('classLevel'), 15);
  t.is(character.get('rank'), MAX_RANK);
});
Example #9
0
 _revealDeep(id: ElementID) {
   if (this.searchRoots && this.searchRoots.contains(id)) {
     return;
   }
   var pid = this._parents.get(id);
   while (pid) {
     if (this._nodes.getIn([pid, 'collapsed'])) {
       this._nodes = this._nodes.setIn([pid, 'collapsed'], false);
       this.emit(pid);
     }
     if (this.searchRoots && this.searchRoots.contains(pid)) {
       return;
     }
     pid = this._parents.get(pid);
   }
 }
Example #10
0
test('You gain level when you reach the maximum XP', t => {
  const reqBaseXp = baseXpData[/* level = */1];
  const reqClassXp = classXpData[/* rank = */0][/* level = */1];
  // note we count ranks from 0
  const state = INITIAL_STATE.setIn(
    ['character', 'initial', 'baseXp'],
    reqBaseXp
  ).setIn(
    ['character', 'initial', 'classXp'],
    reqClassXp
  );
  const character = calculatorReducer(state, { type: CALCULATE })
    .get('character');

  t.is(character.get('baseLevel'), 2);
  t.is(character.get('classLevel'), 2);
});
Example #11
0
 monocellDocument.getIn(['notebook', 'cellOrder']).map((cellID) => {
   cellStatuses = cellStatuses.setIn([cellID, 'outputHidden'], false)
                             .setIn([cellID, 'inputHidden'], false);
   return cellStatuses;
 });
Example #12
0
const setUser = (action) => {
  const { user } = action;

  _users = _users.setIn([user.id], user);
};
Example #13
0
 this.searchRoots.forEach(id => {
   if (this.hasBottom(id)) {
     this._nodes = this._nodes.setIn([id, 'collapsed'], true);
   }
 });
Example #14
0
 /**
  * Sets `value` to a `key`.
  * @param {string|Object|ImmutableMap|any} key
  * @param {any} [value]
  * @returns {Synthetic}
  */
 set(key: string|Object|Map|any, value: any): this {
   if (arguments.length === 1) return this.reset(this.attributes.mergeDeep(key));
   if (Path.is(key)) return this.reset(this.attributes.setIn(Path.to(key), value));
   return this.reset(this.attributes.set(key, value));
 }