Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

christianalfoni [ ] # Title

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Declarative business logic

Slide 10

Slide 10 text

Declarative business logic Context independence Pure functions Referential transparency What not how

Slide 11

Slide 11 text

  • Foo
Declarative

Slide 12

Slide 12 text

const ul = document.createElement(‘ul’) const li = document.createElement(‘li’) li.innerHTML = ‘Foo’ ul.appendChild(li) Imperative

Slide 13

Slide 13 text

const ul = document.createElement(‘ul’) const li = document.createElement(‘li’) li.innerHTML = ‘Foo’ ul.appendChild(li)
  • Foo
(Declarative) Developer to Developer (Imperative) Developer to Computer

Slide 14

Slide 14 text

no declarative without imperative

Slide 15

Slide 15 text

data-structures are declarative

Slide 16

Slide 16 text

const user = new Object() user.name = ‘bob’ const list = new Array() list[0] = ‘apple’ Declarative Imperative const user = { name: ‘bob’ } const list = [ ‘apple’ ]

Slide 17

Slide 17 text

{ tag: ‘ul’, children: [{ tag: ‘li’, children: [‘Foo’] }] }
  • Foo

Slide 18

Slide 18 text

ul([ li([‘Foo’]) ])
  • Foo

Slide 19

Slide 19 text

render( ul([ li([‘Foo’]) ]) , document.body)

Slide 20

Slide 20 text

1. Run functions in a sequence 2. Run functions asynchronously 3. Run functions in parallel 4. Run functions conditionally INTERPRETER

Slide 21

Slide 21 text

render(...) run(...)

Slide 22

Slide 22 text

[ setCurrentPage, setThemeFromLocalStorage ] 1. Run functions in a sequence

Slide 23

Slide 23 text

[ getUser, setUser ] 2. Run functions asynchronously

Slide 24

Slide 24 text

3. Run functions in parallel [ setLoadingApp, parallel([ getNotifications, getArticles ]), unsetLoadingApp ]

Slide 25

Slide 25 text

[ whenUserRole, { admin: changeSetting, user: showError } ] 4. Run functions conditionally

Slide 26

Slide 26 text

1. Set loading state 2. Get user success: Set user and notify success error: Set error and notify error 3. Unset loading state [ setLoading(true), getUser, { success: [setUser, notify(‘User loaded’, ‘success’)], error: [setError, notify(‘User error’, ‘error’)] }, setLoading(false), ]

Slide 27

Slide 27 text

function run () { this.isLoading = true return http.get(‘/user’) .then((response) => { this.user = response.result notifier.add(‘User loaded’, ‘success’) this.isLoading = false }) .catch((error) => { this.error = error notifier.add(‘User error’, ‘error’) this.isLoading = false }) }

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

[ ] Function Tree

Slide 30

Slide 30 text

const ft = new FunctionTree({ axios })

Slide 31

Slide 31 text

const sequence = [ doSomething, somethingElse ] ft.run(sequence, { foo: ‘bar’ })

Slide 32

Slide 32 text

function doSomething ({ axios, props }) { }

Slide 33

Slide 33 text

app.get(‘/articles’, handle([ getUser, roleEquals, { admin: getAdminArticles, user: getUserArticles }, sendArticles ])) export const initialize = thunk([ getUser, dispatch(SET_USER), parallel([ getProfile, getNotifications ]), dispatch(SET_APP_DATA) ]) export const initialize = [ getUser, set(state`auth.user`, props`user`), parallel([ getProfile, getNotes ]), set(state`app.profile`, props`profile`), set(state`app.notes`, props`notes`) ]

Slide 34

Slide 34 text

execution:start function:start function:end function:start function:async function:end path:start sequence:start function:start function:end function:start function:end sequence:end path:end function:start function:end execution:end [ setLoading(true), getUser, { success: [setUser, notify(‘User loaded’, ‘success’)], error: [setError, notify(‘User error’, ‘error’)] }, setLoading(false), ]

Slide 35

Slide 35 text

[ setLoading(true), getUser, { success: [setUser, notify(‘User loaded’, ‘success’)], error: [setError, notify(‘User error’, ‘error’)] }, setLoading(false), ] CRITICAL RENDER

Slide 36

Slide 36 text

[ {type: ‘function’, name: ‘setLoading’}, {type: ‘function’, name: ‘getUser’}, {type: ‘path’, outputs: {} } {type: ‘function’, name: ‘setLoading’}, ]

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

1. Declarative improves developer to developer communication 2. Data structures are the holy grail of declarative 3. Interpret as business logic SUMMARY

Slide 40

Slide 40 text

www.cerebraljs.com [ ]