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 events = { | |
events: {}, | |
on: function (eventName, fn) { | |
this.events[eventName] = this.events[eventName] || []; | |
this.events[eventName].push(fn); | |
}, | |
emit: function (eventName, data) { | |
if (this.events[eventName]) { | |
this.events[eventName].map(function(fn) { | |
fn(data); |
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
// module a.js | |
let a | |
function setValueOfA(val) { | |
a = val | |
// we are now emmiting event 'aChanged' | |
// with data as value of a | |
events.emit('aChanged', a) | |
} | |
// module b.js | |
let b |
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
// module a.js | |
let a | |
function assignValueToA(val) { | |
a = val | |
calculateValueOfB(a) | |
} | |
// module b.js | |
let b | |
function calculateValueOfB(a) { | |
b = a + 100 |
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
// declaring an independent variable | |
let a = 50 | |
// declaring a mathematical constraint between the variable a and b | |
let b = a + 100 | |
// variable b is now holding value 150 | |
console.log(b) // 150 | |
// manipulating value of variable a | |
a = 100 | |
// variable b is still holding value 150 | |
console.log(b) // 150 |
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
// Select the button we need need to listen upon. | |
const myButton = document.querySelector('#click-me') | |
// Create a stream of clicks, using fromEvent function, | |
// by passing the button and the event listener. | |
const click$ = Rx.Observable.fromEvent(myButton, 'click') |
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
// Select the button we need need to listen upon. | |
const myButton = document.querySelector('#click-me') | |
// Create a stream of clicks, using fromEvent function, | |
// by passing the button and the event listener. | |
const click$ = Rx.Observable.fromEvent(myButton, 'click') | |
// From the click stream, we create a new stream, | |
// where we first collect all the clicks | |
// that happen in 250ms inverval of the previous click | |
// and group them together. | |
const dbClick$ = click$.bufferWhen(() => click$.debounceTime(250)) |
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 time$ = Rx.Observable.interval(1000) | |
const filtered$ = time$ | |
.filter(x => x%2 === 0) | |
.map(x => `${x} seconds have passed`) | |
filtered$.subscribe(x => console.log(x)) |
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
{"lastUpload":"2020-06-08T06:36:34.305Z","extensionVersion":"v3.4.3"} |
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
#!/usr/bin/env osascript -l JavaScript | |
const Chrome = Application('Chrome'); | |
// although there is ES6 support , but "run" function | |
// can't use fat arrow functions. | |
// https://github.com/JXA-Cookbook/JXA-Cookbook/wiki/ES6-Features-in-JXA#arrow-functions | |
function run(args) { | |
const url = args[0]; | |
const tabData = findTabForUrl(url); |
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 CounterContext = React.createContext(0); | |
class CounterProvider extends React.Component { | |
state = { count: 0 }; | |
incrementCount = () => { | |
this.setState(({ count }) => ({ count: count + 1 })); | |
}; | |
componentDidMount() { | |
setInterval(this.incrementCount, 1000); | |
} |
OlderNewer