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 expr = '1+23*34+45' | |
| const op_reg = /(\+|-|\*|\/)/; | |
| function tokenize(expr){ | |
| return expr.split(op_reg).map(x => { | |
| if(op_reg.test(x)){ | |
| return x; | |
| }else { | |
| return +x; | |
| } |
In React's terminology, there are five core types that are important to distinguish:
React Elements
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 keepTrying(otherArgs, promise) { | |
| promise = promise||new Promise(); | |
| // try doing the important thing | |
| if(success) { | |
| promise.resolve(result); | |
| } else { | |
| setTimeout(function() { | |
| keepTrying(otherArgs, promise); |
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
| import React,{PropTypes} from 'react'; | |
| // Somewhere in code | |
| <AsyncComponent loader={() => import('./SomeComponent')} /> | |
| // React wrapper for loading | |
| class AsyncComponent extends React.Component { | |
| constructor(props) { | |
| super(props); |
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <title></title> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| </head> | |
| <body> |
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <title></title> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| </head> | |
| <body> |
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
| let subscribers = [] | |
| let activeJob = null | |
| let a = 3 | |
| const state = { | |
| get a() { | |
| if (subscribers.indexOf(activeJob) < 0) { | |
| subscribers.push(activeJob) | |
| } | |
| return a | |
| }, |
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
| let subscribers = [] | |
| let activeJob = null | |
| let a = 3 | |
| const state = { | |
| get a() { | |
| if (subscribers.indexOf(activeJob) < 0) { | |
| subscribers.push(activeJob) | |
| } | |
| return a | |
| }, |
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 async(generator){ | |
| var iterator = generator(); | |
| function handle(iteratorResult){ | |
| if(iteratorResult.done){ return;} | |
| const iteratorValue = iteratorResult.value; | |
| if(iteratorValue instanceof Promise){ | |
| iteratorValue.then(res => handle(iterator.next(res))) | |
| .catch(err => iterator.throw(err)) | |
| } |