Ejemplo n.º 1
0
    receiveWalk(walk);
  }
}

// Get the "outings", or scheduled dates, for our walks
function getWalkOutings() {
  return [..._walks.values()].reduce((arr, walk) => {
    if (walk.time && walk.time.slots) {
      for (const slot of walk.time.slots) {
        arr.push({ walk, slot });
      }
    }
    return arr;
  }, [])
  .sort((a, b) => a.slot[0] - b.slot[0]);
}

const WalkStore = Object.assign({}, Store, {
  getWalks: () => _walks,
  getWalk: (id) => _walks.get(+id),
  getWalkOutings,

  // Register our dispatch token as a static method
  dispatchToken: register2({
    [AT.WALK_RECEIVE]: ({ walk }) => receiveWalk(walk),
    [AT.WALK_RECEIVE_ALL]: ({ walks }) => receiveWalks(walks),
  }, () => WalkStore.emitChange()),
});

export default WalkStore;
Ejemplo n.º 2
0
// Store singletons
// The users, keyed on uID
const _users = new Map();

// Is this the actively logged in user
let _current;

function receiveUser({ user, current }) {
  // Merge users, so we can add more data to the same one.
  const newUser = Object.assign(_users.get(+user.id) || {}, user);
  _users.set(+user.id, newUser);

  if (current) {
    _current = newUser;
  }
}

const UserStore = Object.assign({}, Store, {
  getUsers: () => _users,
  getCurrent: () => _current,

  // Register our dispatch token as a static method
  dispatchToken: register2({
    [AT.USER_RECEIVE]: receiveUser,
    [AT.USER_RECEIVE_ALL]: ({ users }) => users.forEach(user => receiveUser({ user })),
  }, () => UserStore.emitChange()),
});

export default UserStore;
Ejemplo n.º 3
0
// Basic flux setup
import Store from './Store';
import { register2 } from 'janeswalk/dispatcher/AppDispatcher';
import { ActionTypes as AT } from 'janeswalk/constants/JWConstants';

// The library for managing translations
import I18nTranslator from '../utils/translate.js';

// Local vars
const _i18n = new I18nTranslator();

const I18nStore = Object.assign({}, Store, {
  getTranslate: () => _i18n.translate.bind(_i18n),
  getTranslateTag: () => _i18n.translateTag.bind(_i18n),
  getTranslatePlural: () => _i18n.translatePlural.bind(_i18n),

  // Register our dispatch token as a static method
  dispatchToken: register2({
    [AT.I18N_RECEIVE]: ({ translations }) => _i18n.constructor(translations),
  }, () => I18nStore.emitChange()),
});

export default I18nStore;
export const t = I18nStore.getTranslate();
export const t2 = I18nStore.getTranslatePlural();
export const translateTag = I18nStore.getTranslateTag();

// FIXME make this real
export const tc = (c, s) => s;
Ejemplo n.º 4
0
const _log = [];

function receiveLogEntry(message, component, level) {
  _log.push({
    time: Date.now(),
    message,
    level,
  });
}

const NotifyStore = Object.assign({}, Store, {
  getLog: () => _log,
  getLogFrom: (from) => _log.filter(entry => entry.time >= from),

  // Register our dispatch token as a static method
  dispatchToken: register2({
    [AT.LOG_INFO]: ({ message, component = 'caw' }) => {
      receiveLogEntry(message, component, 'info');
    },
    [AT.LOG_WARN]: ({ message, component }) => {
      receiveLogEntry(message, component || 'caw', 'warn');
    },
    [AT.LOG_ERROR]: ({ message, component }) => {
      receiveLogEntry(message, component || 'caw', 'error');
    },
    [AT.LOG_EMPTY]: () => _log.splice(0),
  }, () => NotifyStore.emitChange()),
});

export default NotifyStore;