persistent data structures - good for ui (presented at rubyfuza 2014)

57
@danieroux Persistent data structures, good for UI

Upload: danieroux

Post on 19-May-2015

3.564 views

Category:

Technology


3 download

DESCRIPTION

Persistent data structures are being imported from the FP world. What makes persistent data structures particularly interesting is that they cannot be modified in the traditional sense. These structures can model a timeline of changes quite naturally since every "change" creates a new "copy". "Functional Reactive Programming" is another old/new idea. FRP has a time centric viewpoint. Having persistent data structures on the Javascript/UI side of the world unlocks a lot of the magic that FRP has to offer. In this talk Danie will explain why persistent data structures are good and specifically why they are good for (the) UI.

TRANSCRIPT

Page 1: Persistent data structures - good for UI (presented at Rubyfuza 2014)

@danieroux

Persistent data structures, good for UI

Page 2: Persistent data structures - good for UI (presented at Rubyfuza 2014)

@danieroux

Persistent data structures, good for UI

… You & I (sorry)

Page 3: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Modelling Chess

Page 4: Persistent data structures - good for UI (presented at Rubyfuza 2014)
Page 5: Persistent data structures - good for UI (presented at Rubyfuza 2014)
Page 6: Persistent data structures - good for UI (presented at Rubyfuza 2014)

e2-e4

Page 7: Persistent data structures - good for UI (presented at Rubyfuza 2014)

e2-e4

Page 8: Persistent data structures - good for UI (presented at Rubyfuza 2014)

e2-e4 d7-d6

Page 9: Persistent data structures - good for UI (presented at Rubyfuza 2014)

e2-e4 d7-d6

Page 10: Persistent data structures - good for UI (presented at Rubyfuza 2014)

e2-e4 d7-d6 d2-d4

Page 11: Persistent data structures - good for UI (presented at Rubyfuza 2014)

e2-e4 d7-d6 d2-d4

Page 12: Persistent data structures - good for UI (presented at Rubyfuza 2014)

LIE

Page 13: Persistent data structures - good for UI (presented at Rubyfuza 2014)

The conceptual model does not match reality

Page 14: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Reality

Page 15: Persistent data structures - good for UI (presented at Rubyfuza 2014)
Page 16: Persistent data structures - good for UI (presented at Rubyfuza 2014)
Page 17: Persistent data structures - good for UI (presented at Rubyfuza 2014)

e2-e4

Page 18: Persistent data structures - good for UI (presented at Rubyfuza 2014)

d7-d6

Page 19: Persistent data structures - good for UI (presented at Rubyfuza 2014)

d2-d4

Page 20: Persistent data structures - good for UI (presented at Rubyfuza 2014)

… but what if we keep a move list

Page 21: Persistent data structures - good for UI (presented at Rubyfuza 2014)
Page 22: Persistent data structures - good for UI (presented at Rubyfuza 2014)

1. e2-e4 2. d7-d6 3. d2-d4

Page 23: Persistent data structures - good for UI (presented at Rubyfuza 2014)

1. e2-e4 2. d7-d6 3. d2-d4

Get back here

Page 24: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Move list is not reversible …

Page 25: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Keep all the states

Page 26: Persistent data structures - good for UI (presented at Rubyfuza 2014)
Page 27: Persistent data structures - good for UI (presented at Rubyfuza 2014)
Page 28: Persistent data structures - good for UI (presented at Rubyfuza 2014)
Page 29: Persistent data structures - good for UI (presented at Rubyfuza 2014)
Page 30: Persistent data structures - good for UI (presented at Rubyfuza 2014)
Page 31: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Full History

Page 32: Persistent data structures - good for UI (presented at Rubyfuza 2014)
Page 33: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Partial History

Page 34: Persistent data structures - good for UI (presented at Rubyfuza 2014)

react.js

Page 35: Persistent data structures - good for UI (presented at Rubyfuza 2014)

DeveloperMachine

react.js

Page 36: Persistent data structures - good for UI (presented at Rubyfuza 2014)

DeveloperMachine(person)

react.js

Page 37: Persistent data structures - good for UI (presented at Rubyfuza 2014)

DeveloperMachine(person)

react.js

Page 38: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Virtual DOM

DeveloperMachine(person)

DOM

react.js

Page 39: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Virtual DOM

DeveloperMachine(person)

DOMContinuously

react.js

Page 40: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Virtual DOM

DeveloperMachine(person)

DOMContinuously

Draws newreact.js

Page 41: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Virtual DOM

DeveloperMachine(person)

DOMContinuously

requestAnimationFrame

Draws newreact.js

Page 42: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Virtual DOM

DeveloperMachine(person)

DOMContinuously

requestAnimationFrame

Draws newreact.js

Page 43: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Virtual DOM

DeveloperMachine(person)

DOM

MAGIC

Continuously

requestAnimationFrame

Draws newreact.js

Page 44: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Magic = Tree Diffing

And persistent/immutable data structures make that cheaper

Page 45: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Separating concerns

Page 46: Persistent data structures - good for UI (presented at Rubyfuza 2014)
Page 47: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Rendering

State

Page 48: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Rendering

State

World

Page 49: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Rendering

State

World Logic

Page 50: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Rendering

State

World Logic

TIME

Page 51: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Updates

Rendering

State

World Logic

TIME

Page 52: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Updates

Rendering

State

World Logic

Uses

TIME

Page 53: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Updates

RenderingValue

State

World Logic

Uses

TIME

Page 54: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Snapshots

Updates

RenderingValue

State

World Logic

Uses

TIME

Page 55: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Renders

Snapshots

Updates

RenderingValue

State

World Logic

Uses

TIME

Page 56: Persistent data structures - good for UI (presented at Rubyfuza 2014)

Example code: !

https://github.com/danieroux/rubyfuza2014

Page 57: Persistent data structures - good for UI (presented at Rubyfuza 2014)

@danieroux … let’s have coffee

?

http://facebook.github.io/react https://github.com/swannodette/om

https://github.com/danieroux/rubyfuza2014

Thank you to: http://designindevelopment.com/css/css3-chess-board