/*jshint node: true, browser: true, nomen: true */
/*global projects_ss*/
'use strict';

var Reflux = require('reflux');
var ProjectsStore = Reflux.createStore({
    mixins: [DataHelpers],
    listenables: ProjectsActions,
    init: function () {
        this.listenTo(ProjectStore, this.projectsUpdated);
        this.projects = typeof projects_ss === 'undefined' ? [] : projects_ss;
    },
    projectsUpdated: function (evt) {
        if (evt.success) {
            switch (evt.type) {
                case 'create':
                    this.projects.push(evt.data);
                break;
                case 'addField':
                case 'removeField':
                    this.UpdateArrayById(this.projects, evt.data);
                break;
            }
        }
        this.trigger(this.projects);
    },
    getDefaultData: function () {
        return this.projects;
    }
});

module.exports = ProjectsStore;
var ProjectsActions = require('../actions/projects-actions');
var DataHelpers = require('../mixins/data-helpers');
var ProjectStore = require('./project-store');
