Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Fuck redux! The true story about “Replacing Re...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Jarl André Hübenthal
September 14, 2017
Programming
0
220
Fuck redux! The true story about “Replacing Redux with RxJS”
JavaZone 2017 lightning talk
Jarl André Hübenthal
September 14, 2017
Tweet
Share
More Decks by Jarl André Hübenthal
See All by Jarl André Hübenthal
ReactJS - Replacing Redux with RxJS
jarlah
0
120
Other Decks in Programming
See All in Programming
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
CSC307 Lecture 03
javiergs
PRO
1
490
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
210
dchart: charts from deck markup
ajstarks
3
1k
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
1
2.6k
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
610
izumin5210のプロポーザルのネタ探し #tskaigi_msup
izumin5210
1
140
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
5
800
CSC307 Lecture 01
javiergs
PRO
0
690
Claude Codeと2つの巻き戻し戦略 / Two Rewind Strategies with Claude Code
fruitriin
0
150
ぼくの開発環境2026
yuzneri
0
250
Featured
See All Featured
WCS-LA-2024
lcolladotor
0
450
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
ラッコキーワード サービス紹介資料
rakko
1
2.3M
Building Adaptive Systems
keathley
44
2.9k
It's Worth the Effort
3n
188
29k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
250
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
0
260
Un-Boring Meetings
codingconduct
0
200
How to Ace a Technical Interview
jacobian
281
24k
We Have a Design System, Now What?
morganepeng
54
8k
GitHub's CSS Performance
jonrohan
1032
470k
Chasing Engaging Ingredients in Design
codingconduct
0
120
Transcript
Fuck redux! The true story about “Replacing Redux with RxJS”
JavaZone 2017
About us! Ingar Abrahamsen @ingarabr Jarl André Hübenthal @jarlandreh
What we had to work with React / redux /
redux middlewares / websockets / server side render / <insert npm package x, y and z>
Reactive streams RxJS
Our new hipster stack! Flow / React / RxJS /
Lodash
None
Show us some code! Counter example https://github.com/jarlah/react-rxjs-example/tree/v0.1
// @flow import React from 'react'; export type Props =
{ state: number, increase: (n: number) => mixed , decrease: (n: number) => mixed }; export function CounterPage(props: Props) { return ( <div className="container"> <h1>Counter</h1> <p>{props.state}</p> <button onClick={() => props.increase(1)}>+</button> <button onClick={() => props.decrease(1)}>-</button> </div> ); }
// @flow import { Observable, Subject } from 'rxjs'; import
{ createStore } from 'react-rxjs/dist/RxStore' ; type Number = { n: number }; export const increase$: Subject<Number> = new Subject(); export const decrease$: Subject<Number> = new Subject(); const reducer$ = (actions: *) => Observable. merge( actions.increase$.map(number => state => state + number.n) , actions.decrease$.map(number => state => state - number.n) ); export const store = (actions: *) => createStore('counter', reducer$(actions), 0); export default store({ increase$, decrease$ });
// @flow import store$, { decrease$, increase$ } from './store';
import inject from 'react-rxjs/dist/RxInject' ; import { CounterPage } from './view'; function props(state) { return { state, increase: n => increase$.next({ n }) , decrease: n => decrease$.next({ n }) }; } export default inject(store$, props)(CounterPage);
// @flow import { store } from '../store'; import {
TestScheduler } from 'rxjs/Rx'; describe('counter store', () => { it('increase and decrease', () => { const ts = new TestScheduler((a, b) => expect(a).toEqual(b)); const streams = { inc: '-ab--', dec: '---ab', res: 'abcde' }; const n = { n: 1 }; const increase$ = ts.createHotObservable(streams.inc, { a: n, b: n}); const decrease$ = ts.createHotObservable(streams.dec, { a: n, b: n}); const resultMap = { a: 0, // init b: 1, c: 2, // inc d: 1, e: 0 // dec }; ts.expectObservable(store({ increase$, decrease$ })).toBe(streams.res, resultMap); ts.flush(); }); });
Conclusion Keep it simple, stupid (KISS) Single responsibility principle