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
Jarl André Hübenthal
September 14, 2017
Programming
0
210
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
「待たせ上手」なスケルトンスクリーン、 そのUXの裏側
teamlab
PRO
0
560
Cache Me If You Can
ryunen344
2
3k
1から理解するWeb Push
dora1998
7
1.9k
Laravel Boost 超入門
fire_arlo
3
220
私の後悔をAWS DMSで解決した話
hiramax
4
210
Kiroで始めるAI-DLC
kaonash
2
620
Rancher と Terraform
fufuhu
2
550
Processing Gem ベースの、2D レトロゲームエンジンの開発
tokujiros
2
130
今だからこそ入門する Server-Sent Events (SSE)
nearme_tech
PRO
3
250
アルテニア コンサル/ITエンジニア向け 採用ピッチ資料
altenir
0
110
AWS発のAIエディタKiroを使ってみた
iriikeita
1
190
基礎から学ぶ大画面対応(Learning Large-Screen Support from the Ground Up)
tomoya0x00
0
3.3k
Featured
See All Featured
Making Projects Easy
brettharned
117
6.4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Git: the NoSQL Database
bkeepers
PRO
431
66k
Why Our Code Smells
bkeepers
PRO
339
57k
Documentation Writing (for coders)
carmenintech
74
5k
Imperfection Machines: The Place of Print at Facebook
scottboms
268
13k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
Context Engineering - Making Every Token Count
addyosmani
3
58
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
How GitHub (no longer) Works
holman
315
140k
YesSQL, Process and Tooling at Scale
rocio
173
14k
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