React With
Clojurescript

A Lightning talk
@NagarajanFs

Anyone could learn Lisp in one day, except that if they already knew Fortran, it would take three days.
About Me
Full stack develolper
Fiddle with Js
I Like to
Sr. Software Engineer @ Snapwiz. Inc.,
Amateur Harmonica Player

@NagarajanFs
Tell others what to do
https://github.com/oneto018
Cljs Lightning Course
function add(a,b){
return a+b;
}
//or
const add =
(a, b) => a+b;
add(3,5)(defn add
[a b]
(+ a b))
(add 3 5)a + 5;
(a+b)-c;
f1(f2(8,b),10)(+ a 5)
(- (+ a b) c)
; or
(-> (+ a b)
(- c))
(f1 (f2 8 b))
; or
(-> (f2 8 b)
(f1 10))Cljs Lightning Course
const users = [{ name: "name1", age: 20 },
{ name: "name2", age: 30 }];
(def users [{:name "name1" :age 20}
{:name "name2" :age 30}])var x = 5(def x 5)const user1Age = users[0].age
//or with lodash
const user1Age = _.get(users,[0,"age"])(def user1-age
(get-in users [0 :age]))// both of this will mutate the object
users[0].age = 21
//or with lodash
_.set(users,[0,"age"],21);doesn't update existing and returns the new data
(assoc-in users [0 :age] 21)// this will mutate the object
_.update(users,[0,"age"],(x) => x+1)(update-in users [0 :age] inc) ; or
(update-in users [0 :age] #(+ % 1))Identity, State & Value
- In clojure/clojurescript there is a clear separation between Identity, values and state
- Values represent data.
- Values themselves never changes. 5 is 5 and its value cannot be changed to anything other than 5
- Unlike other languages, this definition not only applies to primitives , but also to all the other data structures (list,vector,map,set,..etc)
Identity, State & Value (contd.)
- But our typical program needs to keep track of some changing Values over time
- State is a value at a point in time
We need to way to identify(reference) this changing State in our programs. We can call that Identity
We need to way to identify(reference) this changing State in our programs. We can call that Identity
Identity, State & Value (contd.)
- By default everything is Value.
- State have to be created explicitly
- Atoms are common and simple abstraction for states provided at language level
(defonce users (atom [{:name "name1" :age 20}
{:name "name2" :age 30}]))
(defn increment-users-age! [users index]
(swap! users update-in [index :age] inc)
(println "users currently before incrementing" @users)
(increment-users-age! users 0)
(println "users currently after incrementing" @users)Time to see the code
clojurescript & react - lightning
By Nagarajan N
clojurescript & react - lightning
- 76