Created
March 21, 2016 12:36
-
-
Save Colmea/9a3e1e1523c3a45d2d9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AltStore from 'alt'; | |
import Dispatcher from '../Dispatcher'; | |
import ProjectActions from '../actions/ProjectActions'; | |
import TransformationActions from '../actions/TransformationActions'; | |
import Project from '../core/Project'; | |
import Timber from '../core/components/Timber'; | |
import Panel from '../core/components/Panel'; | |
class ProjectStoreDefinition implements AltStore { | |
/** | |
* Main user project | |
*/ | |
project: Project; | |
constructor() { | |
this.bindListeners({ | |
renameProject: ProjectActions.RENAME, | |
addComponent: ProjectActions.ADD_COMPONENT, | |
addTransformation: TransformationActions.ADD | |
}); | |
this.project = new Project(); | |
} | |
public getPrice(): number { | |
return this.project.getPrice(); | |
} | |
/** | |
* Get current project | |
* @returns {Project} | |
*/ | |
public getProject(): Project { | |
return this.project; | |
} | |
/** | |
* Rename the project | |
* @param newName | |
*/ | |
renameProject(newName: string): void { | |
this.getProject().rename(newName); | |
} | |
/** | |
* Add a new component in the project | |
* @param data | |
* @returns {boolean} | |
*/ | |
addComponent(data: { componentType: string }): void { | |
// Create component | |
switch(data.componentType){ | |
case 'Timber': | |
var timber = new Timber(data); | |
this.getProject().addComponent(timber); | |
break; | |
case 'Panel': | |
var panel = new Panel(data); | |
this.getProject().addComponent(panel); | |
break; | |
default: | |
console.log('Error: Component type not recognized'); | |
return false; | |
} | |
} | |
} | |
var ProjectStore = Dispatcher.createStore(ProjectStoreDefinition, 'ProjectStore'); | |
export default ProjectStore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment