Interactive Director and Founder
immutable object
an object that cannot be modified after it’s initial creation.
noun
"a string" = "another string"
2 = 3
true = false
null = "i'm not null"
undefined = null
"a really cool string" === "a really cool string"
2 === 2
2 = 3 ?
Object.freeze()
Vector.prototype.push = function(newEl) {
var newVector = deepCopy(this) //step 1
newVector.push(newEl) //step 2
return newVector //step 3
}
That must be slowwwwwwwwwwwwwwww
Ain't nobody got time for that.
vs.
List
HashMap
Concurrency?
But JS is single threaded...
Less complex
Mutable state is the root of all evil.
- Pete Hunt
var a = [0, 1, 2, 3, 4]
var b = a
a.push(5)
console.log(a) // [0, 1, 2, 3, 4, 5]
console.log(b) // [0, 1, 2, 3, 4, 5]
function someFunc(anotherFunc) {
var anObject = {
a: 1,
b: 2
}
anotherFunc(anObject)
console.log(anObject) // I have no idea.
}
import {List, Map} from "immutable"
var list1 = List([0, 1, 2, 3, 4])
var list2 = list1.push(5)
console.log(list1 === list2) // false
var map1 = Map({ a: 1, b: 2 })
var map2 = map1.set("c", 3)
console.log(map1 === map2) // false
console.log(map1) // { a: 1, b: 2 }
console.log(map2) // { a: 1, b: 2, c: 3 }
shouldComponentUpdate()
PureRenderMixin
return !shallowEqual(this.props, nextProps) ||
!shallowEqual(this.state, nextState);
===
+
DATA INSIDE STORES BECOMES IMMUTABLE
PureRenderMixin
+
is fast
but it could be faster...
IMMUTABLE CURSORS INTO GLOBAL APP STATE
ALLOWS FOR INCREDIBLY EFFICIENT
shouldComponentUpdate()
every time the app state changes
(((((((((add 2 2)))))))))
* not actually valid Clojure
+
+
Do we even need Flux with all this coolness?
I think we do...
as
WORK NORMALLY
Entire app re-renders...but efficiently
Deeeeeeep in the component tree
*with Randy Newman
flux.dehydrate() //outputs global app state object
flux.rehydrate(STATE) // here it is on the client!
shouldComponentUpdate()