Top Banner
App state handling with Morearty and React Alexander Savin @karismafilms
33

Application state handling with ReactJS and Morearty

Jun 10, 2015

Download

Technology

alexsavin

Presented on London React User Group meetup on 23.7.2014
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Application state handling with ReactJS and Morearty

App state handlingwith Morearty and React

Alexander Savin@karismafilms

Page 2: Application state handling with ReactJS and Morearty

this.state this.props

Page 3: Application state handling with ReactJS and Morearty

callback: ->@set-state c: it

render: ->…component-b do

prop-a: @state.aprop-b: @state.bprop-c: @callback

Component A

on-change: ->@prop-c value

render: ->div class-name: ‘my-input’,

@transfer-props-to input doplaceholder: @props.prop-aon-change: @on-change

Component B

Page 4: Application state handling with ReactJS and Morearty

State tree

Page 5: Application state handling with ReactJS and Morearty

Flux

Dispatcher

Store A

Component A Component B Component C

Page 6: Application state handling with ReactJS and Morearty
Page 7: Application state handling with ReactJS and Morearty

App state in Om

Root atomComponent A Component Bcursor cursor

Page 8: Application state handling with ReactJS and Morearty

shouldComponentUpdate?

By default always returns true

Page 10: Application state handling with ReactJS and Morearty

Immutability

Page 11: Application state handling with ReactJS and Morearty

Immutability

Page 12: Application state handling with ReactJS and Morearty

Immutable objects

● Easier to reason with

● Thread safe

● Better security

● References instead of copies

Page 13: Application state handling with ReactJS and Morearty

Persistent data structures

● Always preserves the previous version of itself

● Yields a new structure on modify

Page 14: Application state handling with ReactJS and Morearty

Persistent data structures

● Partially persistent

● Fully persistent

● Confluently persistent

● Ephemeral

Page 15: Application state handling with ReactJS and Morearty

Performance

Page 16: Application state handling with ReactJS and Morearty
Page 17: Application state handling with ReactJS and Morearty

Vector

Vectors support efficient addition at the end. They also support efficient random access.

Page 18: Application state handling with ReactJS and Morearty

hash_map

Page 19: Application state handling with ReactJS and Morearty

hash_map

Unlike JavaScript objects Mori PersistentHashMap support complex keys.

It's recommended that you only use immutable values for your keys - numbers, strings or a Mori collection.

http://swannodette.github.io/mori/

Page 20: Application state handling with ReactJS and Morearty

Morearty

Page 21: Application state handling with ReactJS and Morearty

Morearty

● Single app context

● Persistent data structures

● JavaScript

Page 22: Application state handling with ReactJS and Morearty
Page 23: Application state handling with ReactJS and Morearty

Morearty hash_map

Page 24: Application state handling with ReactJS and Morearty

Morearty vector

Page 25: Application state handling with ReactJS and Morearty

Morearty Binding object

● Contains app state

● Allows creation of sub-bindings

● Listeners

Page 26: Application state handling with ReactJS and Morearty

Morearty Context

● Central module

● Access to utils, binding, history, data

structures

Page 27: Application state handling with ReactJS and Morearty

Context

Page 28: Application state handling with ReactJS and Morearty

Context in LiveScript

Page 29: Application state handling with ReactJS and Morearty

App

Page 30: Application state handling with ReactJS and Morearty

App in LiveScript

Page 31: Application state handling with ReactJS and Morearty

App components

https://github.com/Tvaroh/todomvc-moreartyjs/blob/master/js/app.js

Page 32: Application state handling with ReactJS and Morearty

Morearty future development

● RRB trees for vectors

● Better documentation

● Community feedback wanted

https://github.com/Tvaroh/moreartyjs

Page 33: Application state handling with ReactJS and Morearty

Further reading

RRB Trees: http://infoscience.epfl.ch/record/169879/files/RMTrees.pdf

Morearty intro (in russian):http://habrahabr.ru/post/229537/