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
function createArray(length, value) { | |
return Array.apply(null, new Array(length)).map((i, index) => typeof value === 'function' ? value(i, index) : value) | |
} | |
createArray(10, (item, index) => ({ a: index }) ) | |
createArray(10, 'lala') |
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 IItem = { | |
key: number, | |
text: string | |
} | |
const items: IItem[] = [{key: 0, text: ''}] | |
// it says type never[] isn't assignable to type [{ text: string}] | |
for (let index = 1; index < 11; index++) { | |
items.push({ |
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
const str = '__key__dfdsafadf[__index__]kjjkl' | |
const regx = /__(\w+)__/g | |
let keys = []; | |
let res; | |
while((res = regx.exec(str)) !== null) { console.log( keys.push(res[1]) ) } |
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 React from 'react'; | |
var template = function(){return( | |
<form onSubmit={ this.handleFormSubmit.bind(this) } > | |
<input type="text" value={ this.foo } ref="foo" /> | |
<button type="submit">Go!</button> | |
</form> | |
)} |
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 React, { Component } from 'react'; | |
import template from './MyComponentsTemplate'; | |
export class MyComponent extends Component { | |
/* skipping all this */ | |
render() { | |
retun template.call(this) | |
} | |
} |
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 React, { Component } from 'react'; | |
var template = function template() { return( | |
<form onSubmit={ this.handleFormSubmit.bind(this) } > | |
<input type="text" value={ this.foo } ref="foo" /> | |
<button type="submit">Go!</button> | |
</form> | |
)} | |
export class MyComponent extends Component { |
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 React, { Component } from 'react'; | |
export class MyComponent extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
foo: "foo", | |
bar: "bar" | |
} | |
} |
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 React, { Component } from 'react'; | |
import template from './MyComponentsTemplate'; | |
export class MyComponent extends Component { | |
/* skipping all this */ | |
render() { | |
retun template.call(this) | |
} | |
} |
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
(this.get('foobar') || '').trim(); |