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
// For Parent.js | |
var Parent = React.createClass({ | |
getInitialState: function () { | |
return { parentValue: "" }; | |
}, | |
// the callback function is passed to Child as props | |
passValueFunc: function (para) { | |
if (this.state[para] != undefined) { | |
return this.state[para]; |
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
// For Parent.js | |
var Parent = React.createClass({ | |
getInitialState: function () { | |
return { childRef: "childRef" }; | |
}, | |
changeHandler: function () { | |
// use ref to call the instance of Child | |
this.refs[this.state.childRef].getChildValue(); | |
}, |
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
// For Parent.js | |
var Parent = React.createClass({ | |
getInitialState: function () { | |
return { | |
changedValue: "" | |
}; | |
}, | |
// the callback function for changing the text in <input type="text"></input> | |
changeHandler: function (event) { |
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
// For Parent.js | |
var Parent = React.createClass({ | |
render: function () { | |
return ( | |
<div><input onchange="" type="text" value="Parent"></input><child></child></div> | |
); | |
} | |
}); | |
// For Child.js |
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 debounce(func, wait, immediate) { | |
var timeout; | |
return function () { | |
var obj = this, argus = arguments; | |
function delayed () { | |
if (!immediate) { | |
func.apply(obj, argus); | |
} | |
timeout = null; | |
} |
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 timeout; | |
var immediate = true; | |
var wait = 500; | |
$(window).resize(function () { | |
console.log("debounced"); | |
function delayed () { | |
if (!immediate) { | |
//the operation needed | |
} | |
timeout = null; |
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 timeout; | |
$(window).resize(function () { | |
function delayed () { | |
//the operation needed | |
timeout = null; | |
} | |
if (timeout) { | |
clearTimeout(timeout); | |
} | |
timeout = setTimeout(delayed, 500); |
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
(defn debounce-chan | |
"Taken from https://github.com/swannodette/async-tests | |
A little different with original one, write to channel after the interval | |
instead of doing it in the beginning" | |
([source msecs] | |
(debounce-chan (chan) source msecs)) | |
([c source msecs] | |
(go-loop [state ::init | |
last-one nil | |
cs [source]] |
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
lazy($(".castle").toArray()).map(mapFunc) | |
.reduce(reduceFunc) | |
.each(eachFunc); |
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
//show the length of $(".castle") | |
> lazy($(".castle")).size() | |
154 | |
//show the length of functions in $(".castle") | |
> lazy($(".castle")).functions().size() | |
145 |