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 fromSpawn = spawn(function *() { | |
| const someVal = yield new Promise((res, rej) => { | |
| setTimeout(res.bind(null, 'whatevs!!!'), 1000); | |
| }); | |
| bloooBlaahhh | |
| }); | |
| fromSpawn.then((data) => { | |
| console.log('Data from spawn', 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
| const fromSpawn = spawn(function *() { | |
| let rejValFirst, rejValSecond, resValLast; | |
| try { | |
| rejValFirst = yield new Promise((res, rej) => { | |
| setTimeout(rej.bind(null, 'blaaa...first rejected!!!'), 1000); | |
| }); | |
| } catch (err) { | |
| console.error('Inside spawn error', err); |
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
| function spawn(gen) { | |
| const it = gen(); | |
| function _co(method, arg) { | |
| let res; | |
| try { | |
| console.log('***TRY***', method, arg); | |
| res = it[method](arg); | |
| } catch(err) { |
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 fromSpawn = spawn(function *() { | |
| let someVal; | |
| try { | |
| //reject a promise | |
| someVal = yield new Promise((res, rej) => { | |
| setTimeout(rej.bind(null, 'whatevs!!!'), 1000); | |
| }); | |
| } catch (err) { |
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
| export default function (dataBindings) { | |
| @provideReactor(dataBindings || {}) | |
| @nuclearComponent((props) => { | |
| const {Getters, modalId} = props; | |
| return { | |
| modalState: [...Getters.modalState, modalId] | |
| } | |
| }) | |
| return class Modal extends Component { |
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 fromSpawn = spawn(function *() { | |
| const someVal = yield new Promise((res, rej) => { | |
| setTimeout(res.bind(null, 'whatevs!!!'), 5000); | |
| }); | |
| console.log(someVal); | |
| return `I decided to return => ${someVal}`; | |
| }); | |
| fromSpawn.then((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
| const fromSpawn = spawn(function *() { | |
| const someVal = yield new Promise((res, rej) => { | |
| setTimeout(res.bind(null, 'whatevs!!!'), 5000); | |
| }); | |
| console.log(someVal); | |
| }); | |
| fromSpawn.then((data) => { | |
| console.log('Data from spawn', 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
| /** | |
| * Create a `spawn` function to deal with promises | |
| * http://blog.mgechev.com/2014/12/21/handling-asynchronous-calls-with-es6-javascript-generators/ | |
| */ | |
| function spawn(gen) { | |
| const it = gen(); //instantiate the generator and return the generator object | |
| function _co(method, arg) { | |
| let res; |
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
| @provideContextAsProps({ | |
| Actions: PropTypes.object.isRequired, | |
| Getters: PropTypes.object.isRequired, | |
| moreStuff: PropTypes.object, | |
| stuffFromParent: PropTypes.func.isRequired | |
| }) | |
| @nuclearComponent((props) => { | |
| const {someChildProps, stuffFromParent, Getters, Actions} = props; | |
| stuffFromParent(someChildProps, (arg) => { |
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
| run(function *() { | |
| const thunkedRead = thunk(fs.readFile); | |
| try { | |
| const contents = yield thunkedRead('/path/to/my/dope/file.js'); | |
| console.log(contents.toString()); | |
| } catch (err) { | |
| console.log('Uh Oh', err); | |
| } | |
| }); |