Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Reactive Programming with React
Search
Robin van der Vleuten
June 19, 2017
Technology
94
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Reactive Programming with React
The talk I gave at the "Battle of the Titans" meetup at Spilberg.
Robin van der Vleuten
June 19, 2017
Other Decks in Technology
See All in Technology
SAENM ~Jupyterで残すPoCの試行錯誤、未来の自分と仲間を助ける記録!~
terapyon
0
110
PHPカンファレンス関西の招待状 / Invitation to PHP Conference Kansai
ykanoh
0
140
WasmをRustにする
sansantech
PRO
0
250
QA4AI 2026-Oct 生成AI時代の品質保証
tokuty
1
860
Metadata - Section 1: HTML Basics
mohab1
0
120
USB PDを使ってスマホを労わりたい
raspython3
0
180
OptunaHub: ブラックボックス最適化のためのプラットフォーム
pfn
PRO
0
140
NDIでApple Vision Proにリアルタイム映像送信
jyouryuusui
0
120
[JAWS-UG彩の国埼玉#12]そろそろ準備する?re:Invent2026をやさしく解説 / reinvent2026-sainokuni
sh_fk2
1
340
Classmethod Company Deck
satoshi7
1
700
継続的なAIコスト最適化
bgpat
1
340
Code for Security プロジェクト紹介 2026年10月
yu23ki14
0
110
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
28
2.9k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
300
Rails Girls Zürich Keynote
gr2m
96
14k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
Believing is Seeing
oripsolob
1
240
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
460
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Are puppies a ranking factor?
jonoalderson
2
4.1k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
430
Code Review Best Practice
trishagee
74
20k
Transcript
None
{ "name": "Robin van der Vleuten", "role": "Indepentent Developer", "stack":
[ "PHP", "Symfony", "Laravel", "Javascript", "React (+ Preact)”, "Node.js", "Hapi.js" ], "company": "The Webstronauts", "website": "www.robinvdvleuten.nl", "social": { "twitter": "@robinvdvleuten", "github": "robinvdvleuten" } }
None
function (x) { return x + 1; } function (x,
y) { return x + y; }
(x) { return x + 1; } (x, y) {
return x + y; }
(x) { return x + 1; } (x, y) {
return x + y; }
(x) => { return x + 1; } (x, y)
=> { return x + y; }
(x) => return x + 1; (x, y) => return
x + y;
x => x + 1; (x, y) => x +
y;
[1, 2, 3].forEach(x => console.log(x)); forEach()
[1, 2, 3].filter(x => x > 2); filter()
[1, 2, 3].map(x => x + 1); map()
[1, 2, 3].reduce((total, x) => total + x, 0); reduce()
Your functions are not dependent on context and should have
no “side effects”
const addToCart = (cart, item, quantity) => { cart.push({ item,
quantity }); return cart; }; an “impure” function
const addToCart = (cart, item, quantity) => { return [
...cart, { item, quantity }]; }; a “pure” function
FLUX
None
REDUX Provides predictable state management using actions and reducers
REDUCER (state, action) => state (state, action) => state +
action.payload
ACTION { type: 'CREATE_TODO', payload: 'Build my first Redux app'
}
DISPATCHING ACTIONS <button onClick={() => dispatch({ type: 'INCREASE' })}> Increase
Counter </button>
DISPATCHING ACTIONS const increaseCounter = () => ({ type: 'INCREASE'
}) <button onClick={() => dispatch(increaseCounter())}> Increase Counter </button>
DISPATCHING ACTIONS const increaseeCounter = () => ({ type: 'INCREASE'
}) <button onClick={props.increaseCounter}> Increase Counter </button> connect(null, { increaseCounter })(button)
const counter = (state = 0, action) => { switch
(action.type) { case 'INCREASE': return state + 1; case 'DECREASE': return state - 1; default: return state; } }
ASYNCHRONOUS IN JS User interactions (mouse, keyboard, touch, etc) AJAX
Timers Animations Web Sockets
MIDDLEWARE const logger = store => next => action =>
{ console.log('dispatching', action) let result = next(action) console.log('next state', store.getState()) return result }
REDUX-THUNK
export const fetchAllAsyncData = () => { return dispatch =>
{ fetchAsyncData(id, (err, data) => { if (err) { dispatch({ type: 'ASYNC_FAILURE', err }); } fetchAsyncData(data.parent, (err, data) => { if (err) { dispatch({ type: 'ASYNC_FAILURE', err }); } fetchAsyncData(data.parent, (err, data) => { if (err) { dispatch({ type: 'ASYNC_FAILURE', err }); } dispatch({ type: 'ASYNC_SUCCESS', data }); }); }); }); } }
export const fetchAllAsyncData = () => { return dispatch =>
{ return fetchAsyncData(id) .then(data => { return fetchAsyncData(data.parent); }) .then(data => { return fetchAsyncData(data.parent); }) .then(data => { dispatch({ type: 'ASYNC_SUCCESS', data }); }) .catch(err => { dispatch({ type: 'ASYNC_FAILURE', err }); }); } }
• fulfilled - The action relating to the promise succeeded
• rejected - The action relating to the promise failed • pending - Hasn't fulfilled or rejected yet • settled - Has fulfilled or rejected And a Promise can only return a single value A Promise can be
None
RXJS
/* Get stock data somehow synchronous */ const source =
getSyncStockData(); const subscription = source .filter(quote => quote.price > 30) .map(quote => quote.price) .forEach(price => console.log(`Prices higher than $30: ${price}`));
/* Get stock data somehow asynchronous */ const source =
getAsyncStockData(); const subscription = source .filter(quote => quote.price > 30) .map(quote => quote.price) .subscribe( price => console.log(`Prices higher than $30: ${price}`), err => console.log(`Something went wrong: ${err.message}`) ); /* When we're done */ subscription.dispose()
REDUX-OBSERVABLE
const pingEpic = action$ => action$.filter(action => action.type === 'PING')
.mapTo({ type: 'PONG' }); // later... dispatch({ type: 'PING' });
const pingEpic = action$ => action$.ofType(‘PING') .delay(1000) // Asynchronously wait
1000ms then continue .mapTo({ type: 'PONG' }); // later... dispatch({ type: 'PING' });
// action creators const fetchUser = username => ({ type:
FETCH_USER, payload: username }); const fetchUserFulfilled = payload => ({ type: FETCH_USER_FULFILLED, payload }); // epic const fetchUserEpic = action$ => action$.ofType(FETCH_USER) .mergeMap(action => ajax.getJSON(`https://api.github.com/users/${action.payload}`) .map(response => fetchUserFulfilled(response)) ); // later... dispatch(fetchUser('robinvdvleuten'));
describe('fetchUserEpic', () => { it('should return an user object on
success', async () => { expect.assertions(2); const user = { username: 'robinvdvleuten' }; const response = Observable.of(forms); const ajax = { getJSON: jest.fn() }; ajax.getJSON.mockReturnValueOnce(response); const actions$ = ActionsObservable.of(fetchUser('robinvdvleuten')); const actions = await epics(actions$, store, { ajax }) .toArray() .toPromise(); expect(actions).toEqual([ { type: FETCH_USER, payload: 'robinvdvleuten' }, { type: FETCH_USER_FULFILLED, user }, ]); expect(request).toHaveBeenCalledWith('https://api.github.com/users/robinvdvleuten'); }); });
// action creators const fetchUser = username => ({ type:
FETCH_USER, payload: username }); const fetchUserFulfilled = payload => ({ type: FETCH_USER_FULFILLED, payload }); // epic const fetchUserEpic = (action$, getStore, { ajax }) => action$.ofType(FETCH_USER) .mergeMap(action => ajax.getJSON(`https://api.github.com/users/${action.payload}`) .map(response => fetchUserFulfilled(response)) ); // later... dispatch(fetchUser('robinvdvleuten'));
With redux-observable one can manage any business logic over any
time period
@robinvdvleuten