demand driven applications with om.next and react native

Post on 12-Apr-2017

1.104 Views

Category:

Engineering

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Demand-driven architecture

Problems of the current architecture

= REST?

Let’s do some REST!

Let’s build an app

- post things

- comment on things

- … profit?

Posts

Users

Comments

Let’s build an app

Let’s build an app

Problems?

- unnecessary complex ajax orchestration

- edge cases

- many points of failure

- a lot of data to download

- one part always waits for the other

Let’s build an app

Let’s build an app

Problems?

- duplication of data

- maintenance

- cascading changes through the entire app

- one part always waits for the other

The solution

- Stop endpoint overload

- Shift ownership over data to client

- Server returns exactly what the client needs

- Exactly what netflix and facebook independently did!

om

Disclaimer

- Examples are in clojure

“Client describes data it needs”

(defui Post Object (render [this] (view nil (text nil (get (om/props this) :username)) (text nil (get (om/props this) :content)))))

“Client describes data it needs”

(defui Post static om/IQuery (query [this] '[{:user [:username]} :content]) Object (render [this] (view nil (text nil (get (get (om/props this) :user) :username)) (text nil (get (om/props this) :content)))))

“Client describes data it needs”

(defui Post static om/Ident (ident [this {:keys [id]}] [:post/by-id id]) static om/IQuery (query [this] '[{:user [:username]} :content :id]) Object (render [this] (view nil (text nil (get (get (om/props this) :user) :username)) (text nil (get (om/props this) :content)))))

“Client describes data it needs”

(defui TimelineComponent static om/IQuery (query [this] (let [subquery (om/get-query Post)] `[{:app/posts ~subquery}])) Object (render [this] (let [{:keys [app/posts]} (om/props this)] (view nil (apply view nil (map post posts))))))

DEMO

Advantages?

- server API doesn’t need updates

- downloaded data is as small as possible

- no ajax coordination

- focus is on client and components

- component re-usability

- usable today

- (clojurescript)

Talks

- “om next” by David Nolen

- “Why Falcor?” by Jafar Husain

- “Relay: An application framework for React” by Josep Savona

Questions?

top related