# All files / src/stores store.js

84% Statements 21/25
60% Branches 6/10
83.33% Functions 5/6
84% Lines 21/25

    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
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    2x

    1x

    1x

     import Reflux from 'reflux';
    import StateMixin from 'reflux-state-mixin';
    import { ENTERPRISE, COMMUNITY } from 'constants/server-version';

    /**
     * Server Version store.
     */
    const ServerVersionStore = 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],

      /**
       * This method is called when all plugins are activated. You can register
       * listeners to other plugins' stores here, e.g.
       *
       * appRegistry.getStore('OtherPlugin.Store').listen(this.otherStoreChanged.bind(this));
       *
       * If this plugin does not depend on other stores, you can delete the method.
       *
       * @param {Object} appRegistry - app registry containing all stores and components
       */
      onActivated(appRegistry) {
        appRegistry.getStore('App.InstanceStore').listen(this.onInstanceFetched.bind(this));
      },

      /**
       * Handle an instance fetch.
       *
       * @param {Object} state - The instance store state.
       */
      onInstanceFetched(state) {
        this.setState({
          versionDistro: state.instance.build.enterprise_module ? ENTERPRISE : COMMUNITY,
          versionNumber: state.instance.build.version
        });
      },

      /**
       * Initialize the Server Version 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 {
          versionDistro: '',
          versionNumber: ''
        };
      }
    });

    export default ServerVersionStore;
    export { ServerVersionStore };