# All files / src/stores store.js

35.71% Statements 10/28
50% Branches 4/8
16.67% Functions 1/6
35.71% Lines 10/28

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    3x

     import Reflux from 'reflux';
    import StateMixin from 'reflux-state-mixin';
    import PreferencesActions from 'actions';
    import { Preferences } from 'models';

    /**
     * Preferences store.
     */
    const PreferencesStore = Reflux.createStore({
      /**
       * adds a state to the store, similar to React.Component's state
       * @see https://github.com/yonatanmn/Super-Simple-Flux#reflux-state-mixin
       *
       * If you call `this.setState({...})` this will cause the store to trigger
       * and push down its state as props to connected components.
       */
      mixins: [StateMixin.store],

      /**
       * listen to all actions defined in ../actions/index.jsx
       */
      listenables: PreferencesActions,

      /**
       * When the application is connected we can fetch the app preferences.
       */
      onConnected() {
        this.state.preferences.fetch({
          success: () => {
            this.trigger(this.state);
          }
        });
      },

      /**
       * Initialize the Preferences store state. The returned object must
       * contain all keys that you might want to modify with this.setState().
       *
       * @return {Object} initial store state.
       */
      getInitialState() {
        return {
          preferences: new Preferences()
        };
      }
    });

    export default PreferencesStore;
    export { PreferencesStore };