Created
February 18, 2018 08:11
-
-
Save mynameislau/99cef312bbdd4bcd7d3c0a424df0d64d 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
[...] | |
type mainData = { | |
gActions: list(gAction), | |
entities: list(entity), | |
history: list(historyChunk), | |
resources: int | |
}; |
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
open MainModel; | |
let createInitData = () : mainData => { | |
gActions: [], | |
entities: [EntityFactories.crewMemberFactory(0, 0), EntityFactories.crewMemberFactory(1, 0)], | |
history: [], | |
resources: 1000 | |
}; |
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
let reduce = (state: MainModel.mainData, action: Actions.anyAction) => | |
switch action { | |
| Actions.TickAction => {...state, resources: state.resources + 1} | |
| Actions.AddGActionAction => state | |
}; |
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
let component = ReasonReact.reducerComponent("MyForm"); | |
let make = _children => { | |
...component, | |
initialState: MainModelCreator.createInitData, | |
reducer: (action, state) => | |
/* this is only a simple pattern matching reducer */ | |
ReasonReact.Update(MainReducer.reduce(state, action): MainModel.mainData), | |
render: self => { | |
<div> | |
<button | |
onClick=(_event => self.send(Actions.TickAction)) | |
/> | |
/* Error : Unbound record field resources at <anonymous> */ | |
(ReasonReact.stringToElement(string_of_int(self.state.resources))) | |
</div>; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment