This file contains hidden or 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
| const {fromJS} = Immutable; | |
| const subedit = (edit, ...path) => transform => | |
| edit(state => state.updateIn(path, transform)); | |
| const data = fromJS({ | |
| phone: '6665552222' | |
| }); | |
| const parsePhone = v => v.replace(/\D/g, '').substr(0,10); |
This file contains hidden or 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
| // ComponentRenderMixin is a slightly modified version of PureRenderMixin | |
| const ComponentRenderMixin = require('component-render-mixin'); | |
| function delegate(delegee) { | |
| var delegate = function() { | |
| return delegate.delegee.apply(this, arguments); | |
| } | |
| delegate.delegee = delegee; | |
| delegate.isDelegate = true; | |
| return delegate; |
This file contains hidden or 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
| // @param additionalMixins? {Array|Object} | |
| // @param renderFn {Function} | |
| // @returns Component | |
| function component(additionalMixins, renderFn) { | |
| renderFn = renderFn || additionalMixins; | |
| additionalMixins = (additionalMixins instanceof Function) ? [] : [].concat(additionalMixins); | |
| const mixins = [ComponentRenderMixin].concat(additionalMixins); | |
| const render = function() { |
This file contains hidden or 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
| const {fromJS} = require('immutable'); | |
| const data = fromJS({ name: 'gilbox' }); | |
| const Hello = component(function Hello ({name}, {edit}) { | |
| return <div> | |
| Hello, {name}! | |
| <button onClick={event => edit(name => 'Maude Lebowski') }> | |
| Change My Name | |
| </button> | |
| </div> |
This file contains hidden or 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
| const {fromJS} = require('immutable'); | |
| const data = fromJS({ name: 'gilbox' }); | |
| const Hello = component(function Hello ({name}, {edit}) { | |
| return <div> | |
| Hello, {name}! | |
| <button onClick={event => edit(data => data.updateIn(['name'], 'Maude Lebowski') }> | |
| Change My Name | |
| </button> | |
| </div> |
This file contains hidden or 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
| const subedit = (edit, ...path) => transform => | |
| edit(state => state.updateIn(path, transform)); |
This file contains hidden or 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
| const {fromJS} = require('immutable'); | |
| const data = fromJS({ name: 'gilbox' }); | |
| const rendererMixin = { | |
| getInitialState() { | |
| return {data:this.props.data} | |
| }, | |
| edit (transform) { | |
| this.setState({data: transform(this.state.data)}) | |
| } |
This file contains hidden or 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
| var Transit = require('transit-js'), | |
| Imm = require('immutable'); | |
| // gil: It's possible that the following reader/writer configuration is incomplete. | |
| // This is a modified version of: | |
| // https://gist.github.com/Tvaroh/52efbe8f4541ca537908 | |
| var reader = Transit.reader('json', { | |
| mapBuilder: { | |
| init: function () { return {}; }, |
This file contains hidden or 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
| var Transit = require('transit-js'), | |
| Imm = require('immutable'); | |
| // gil: It's possible that the following reader/writer configuration is incomplete. | |
| // This is a modified version of: | |
| // https://gist.github.com/Tvaroh/52efbe8f4541ca537908 | |
| // | |
| // ... the original version of this utilized built-in JS (ES6?) types for | |
| // better efficiency+speed. However, it didn't work with nested Map + OrderedMap. | |
| // Improved efficiency+speed can be achieved by re-implementing with some native types. |
This file contains hidden or 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
| // | |
| // ui-router | |
| // | |
| $stateProvider.state('person', { | |
| url: '/person/{personId}', | |
| resolve: ($stateParams, AppObject) => { | |
| return AppObject.getPerson( $stateParams.personId ) | |
| }, | |
| controller() { /* ... */ } |