SlideShare a Scribd company logo
1 of 30
Download to read offline
TAO and the Essence of Modern
JavaScript
Valeri Karpov
June 21, 2018
JavaScript Zagreb #42
About Me
● Maintainer of Mongoose (#72 on npm-rank)
● Lead Backend Engineer @ Booster
● Blogger, thecodebarbarian.com
What This Talk is About
● Redux, MobX, ngrx, etc. are the same thing
● They’re fundamentally different from MVC
● What does “one-way data flow” mean for API devs?
● How we use TAO at Booster
Principles of Modern State Management
● Type: data is represented by plain objects (POJO)
● Actions: function calls are represented by POJOs
● Observables: stream of all actions in the system
● TAO: Type-action-observable, as opposed to MVC
Part 1: TAO vs MVC
● Model: data notifies controller of changes
● Controller: changes model, listens to changes
● View: DOM state
The Problem with MVC in JS
● When did something change and how?
With Immutable POJOs, Diffing is Easy
● Assume all changes went through `=` operator
● Objects are serializable and diffing is easy
T is for “Type”
● Data is a POJO (or Immutable.js)
● Data is serializable
● Data is not “hydrated”: Mongoose, Ember, Vue 1.x
● Think “store” in Redux, ngrx, or MobX
Notifying of Changes is Hard
● Proxies, Object.defineProperty() are not POJOs
● Need to “hydrate” object to get change tracking
● RIP Object.observe(), 2011-2015
A is for “Action”
● All changes are represented by an object
● A Redux action is an object representing a fn call
But How Do You Watch for Changes?
● Object representation of function call is useful:
○ Debugging
○ Logging
○ “Time Travelling Debugger”
● But how does this help with change tracking?
O is for “Observable”
● Doesn’t necessarily need to be an observable
● Anything that lets you see all actions:
○ Node.js stream or event emitter
○ Redux middleware
○ ngrx effects
Redux from the TAO Perspective
● Type: State, store.getState()
● Action: Redux actions, store.dispatch()
● Observable: middleware, reducer, React view
ngrx from the TAO Perspective
● Type: State from @ngrx/store
● Action: Actions, store.dispatch()
● Observable: Observables, Effects @ngrx/effects
Vuex from the TAO Perspective
● Type: State
● Action: Actions
● Observable: Mutations, views
Part 2: Server Dev
● Do APIs really need change tracking?
● MVC is painful for REST APIs
● V in MVC = JSON object?
Change Tracking for APIs
● API calls are short-lived
● Browser app lives for a long time, lot of actions
● The “store” is the database
Change Tracking for APIs
● Mongoose, SQL ORMs track changes on objects
● Convert language operations to DB operations
TAO for API Devs
● Type: data coming into the system
● Action: object representation of fn call
● Observable: see all actions in the system
TAO for API Devs
● Can’t validate entire “state”, databases are huge
● Can validate data coming in
● Each action can define what data is valid
● Archetype: data validation lib
TAO for API Devs
● One API call is usually one action
● Object representation for logging
● Pro tip: request ids
● Convert curl =>
TAO for API Devs
● Actions read/write from db, but don’t do everything
● Logging, error handling, slack notifications, etc.
● “Cross-cutting concerns”
● Aspect oriented programming
Part 3: TAO at Booster
● We’ve open-sourced archetype and tao-js on npm
Archetype TAO.js
Part 3: TAO at Booster
● A type is a constructor that throws if casting fails
Part 3: TAO at Booster
● An action is a function, it validates data using types
Part 3: TAO at Booster
● Middleware (locking, error handling)
Part 3: TAO at Booster
● Homebaked observable lib, because of RxJS issues
● Triggers: like middleware, but reactive
What’s Wrong with RxJS?
● Observable = multi-value, single error
● Uncaught error in map() => dead, silent failures
Further Reading
● TAO examples: github.com/vkarpov15/tao
● TAO API docs: bit.ly/tao-api-docs
● Archetype: github.com/boosterfuels/archetype
● Archetype on Twitter: twitter.com/archetype_js
Thanks For Listening!
Slides on Twitter,
@code_barbarian

More Related Content

What's hot

Sprint Boot & Kotlin - Meetup.pdf
Sprint Boot & Kotlin - Meetup.pdfSprint Boot & Kotlin - Meetup.pdf
Sprint Boot & Kotlin - Meetup.pdfChristian Zellot
 
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...Geshan Manandhar
 
kranonit S04E02 Кирил Jstor: Hacking .NET applications
kranonit S04E02 Кирил Jstor: Hacking .NET applicationskranonit S04E02 Кирил Jstor: Hacking .NET applications
kranonit S04E02 Кирил Jstor: Hacking .NET applicationsKrivoy Rog IT Community
 
Scala laboratory: Globus. iteration #3
Scala laboratory: Globus. iteration #3Scala laboratory: Globus. iteration #3
Scala laboratory: Globus. iteration #3Vasil Remeniuk
 
Sexy Architecting. VIPER: MVP on steroids
Sexy Architecting. VIPER: MVP on steroidsSexy Architecting. VIPER: MVP on steroids
Sexy Architecting. VIPER: MVP on steroidsDmytro Zaitsev
 
Intro to Flux - ReactJS Warsaw #1
Intro to Flux - ReactJS Warsaw #1Intro to Flux - ReactJS Warsaw #1
Intro to Flux - ReactJS Warsaw #1Damian Legawiec
 
Business layer and transactions
Business layer and transactionsBusiness layer and transactions
Business layer and transactionsOndrej Mihályi
 
Functional programming
Functional programmingFunctional programming
Functional programmingijcd
 

What's hot (9)

Sprint Boot & Kotlin - Meetup.pdf
Sprint Boot & Kotlin - Meetup.pdfSprint Boot & Kotlin - Meetup.pdf
Sprint Boot & Kotlin - Meetup.pdf
 
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
 
kranonit S04E02 Кирил Jstor: Hacking .NET applications
kranonit S04E02 Кирил Jstor: Hacking .NET applicationskranonit S04E02 Кирил Jstor: Hacking .NET applications
kranonit S04E02 Кирил Jstor: Hacking .NET applications
 
Scala laboratory: Globus. iteration #3
Scala laboratory: Globus. iteration #3Scala laboratory: Globus. iteration #3
Scala laboratory: Globus. iteration #3
 
Sexy Architecting. VIPER: MVP on steroids
Sexy Architecting. VIPER: MVP on steroidsSexy Architecting. VIPER: MVP on steroids
Sexy Architecting. VIPER: MVP on steroids
 
Intro to Flux - ReactJS Warsaw #1
Intro to Flux - ReactJS Warsaw #1Intro to Flux - ReactJS Warsaw #1
Intro to Flux - ReactJS Warsaw #1
 
Business layer and transactions
Business layer and transactionsBusiness layer and transactions
Business layer and transactions
 
XML Quick Fixes
XML Quick FixesXML Quick Fixes
XML Quick Fixes
 
Functional programming
Functional programmingFunctional programming
Functional programming
 

Similar to TAO and the Essence of Modern JavaScript

Building React Applications with Redux
Building React Applications with ReduxBuilding React Applications with Redux
Building React Applications with ReduxFITC
 
Globant development week / React Redux Rorkshop
Globant development week / React Redux RorkshopGlobant development week / React Redux Rorkshop
Globant development week / React Redux RorkshopGlobant
 
Reactive programming
Reactive programmingReactive programming
Reactive programmingNick Hodge
 
Five android architecture
Five android architectureFive android architecture
Five android architectureTomislav Homan
 
JS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
JS Fest 2018. Anna Herlihy. How to Write a Compass PluginJS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
JS Fest 2018. Anna Herlihy. How to Write a Compass PluginJSFestUA
 
Spark Workflow Management
Spark Workflow ManagementSpark Workflow Management
Spark Workflow ManagementRomi Kuntsman
 
MongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To TransactionsMongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To TransactionsMydbops
 
MongoDB WiredTiger Internals: Journey To Transactions
  MongoDB WiredTiger Internals: Journey To Transactions  MongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To TransactionsM Malai
 
Angular training-course-syllabus
Angular training-course-syllabus Angular training-course-syllabus
Angular training-course-syllabus Training Institute
 
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
"Node.js vs workers — A comparison of two JavaScript runtimes", James M SnellFwdays
 
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...Kaxil Naik
 
Design & Develop Batch Applications in Java/JEE
Design & Develop Batch Applications in Java/JEEDesign & Develop Batch Applications in Java/JEE
Design & Develop Batch Applications in Java/JEENaresh Chintalcheru
 
There is REST and then there is "REST"
There is REST and then there is "REST"There is REST and then there is "REST"
There is REST and then there is "REST"Radovan Semancik
 
Building robust apps
Building robust appsBuilding robust apps
Building robust appsCharles Neveu
 
Oslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep DiveOslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep Divedavanum
 
Going Reactive with Spring 5
Going Reactive with Spring 5Going Reactive with Spring 5
Going Reactive with Spring 5Drazen Nikolic
 

Similar to TAO and the Essence of Modern JavaScript (20)

Building React Applications with Redux
Building React Applications with ReduxBuilding React Applications with Redux
Building React Applications with Redux
 
Globant development week / React Redux Rorkshop
Globant development week / React Redux RorkshopGlobant development week / React Redux Rorkshop
Globant development week / React Redux Rorkshop
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Five android architecture
Five android architectureFive android architecture
Five android architecture
 
JS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
JS Fest 2018. Anna Herlihy. How to Write a Compass PluginJS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
JS Fest 2018. Anna Herlihy. How to Write a Compass Plugin
 
Spark Workflow Management
Spark Workflow ManagementSpark Workflow Management
Spark Workflow Management
 
Introduction to Redux.pptx
Introduction to Redux.pptxIntroduction to Redux.pptx
Introduction to Redux.pptx
 
MongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To TransactionsMongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To Transactions
 
MongoDB WiredTiger Internals: Journey To Transactions
  MongoDB WiredTiger Internals: Journey To Transactions  MongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To Transactions
 
Angular training-course-syllabus
Angular training-course-syllabus Angular training-course-syllabus
Angular training-course-syllabus
 
Redux workshop
Redux workshopRedux workshop
Redux workshop
 
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
 
Apache airflow
Apache airflowApache airflow
Apache airflow
 
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
 
Design & Develop Batch Applications in Java/JEE
Design & Develop Batch Applications in Java/JEEDesign & Develop Batch Applications in Java/JEE
Design & Develop Batch Applications in Java/JEE
 
There is REST and then there is "REST"
There is REST and then there is "REST"There is REST and then there is "REST"
There is REST and then there is "REST"
 
Building robust apps
Building robust appsBuilding robust apps
Building robust apps
 
Oslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep DiveOslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep Dive
 
Ngrx: Redux in angular
Ngrx: Redux in angularNgrx: Redux in angular
Ngrx: Redux in angular
 
Going Reactive with Spring 5
Going Reactive with Spring 5Going Reactive with Spring 5
Going Reactive with Spring 5
 

More from Valeri Karpov

A Practical Introduction to GeoJSON
A Practical Introduction to GeoJSONA Practical Introduction to GeoJSON
A Practical Introduction to GeoJSONValeri Karpov
 
A Practical Introduction to Functions-as-a-Service
A Practical Introduction to Functions-as-a-ServiceA Practical Introduction to Functions-as-a-Service
A Practical Introduction to Functions-as-a-ServiceValeri Karpov
 
A Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-ServiceA Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-ServiceValeri Karpov
 
Introducing Async/Await
Introducing Async/AwaitIntroducing Async/Await
Introducing Async/AwaitValeri Karpov
 
Mastering Async/Await in JavaScript
Mastering Async/Await in JavaScriptMastering Async/Await in JavaScript
Mastering Async/Await in JavaScriptValeri Karpov
 
React, Redux, and Archetype
React, Redux, and ArchetypeReact, Redux, and Archetype
React, Redux, and ArchetypeValeri Karpov
 
TDD a REST API With Node.js and MongoDB
TDD a REST API With Node.js and MongoDBTDD a REST API With Node.js and MongoDB
TDD a REST API With Node.js and MongoDBValeri Karpov
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS LimitationsValeri Karpov
 
MongoDB MEAN Stack Webinar October 7, 2015
MongoDB MEAN Stack Webinar October 7, 2015MongoDB MEAN Stack Webinar October 7, 2015
MongoDB MEAN Stack Webinar October 7, 2015Valeri Karpov
 
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...Valeri Karpov
 
Lessons in Open Source from the MongooseJS ODM
Lessons in Open Source from the MongooseJS ODMLessons in Open Source from the MongooseJS ODM
Lessons in Open Source from the MongooseJS ODMValeri Karpov
 
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)Valeri Karpov
 
MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
MongoDB Miami Meetup 1/26/15: Introduction to WiredTigerMongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
MongoDB Miami Meetup 1/26/15: Introduction to WiredTigerValeri Karpov
 
MongoDB API Talk @ HackPrinceton
MongoDB API Talk @ HackPrincetonMongoDB API Talk @ HackPrinceton
MongoDB API Talk @ HackPrincetonValeri Karpov
 
MEAN Stack WeNode Barcelona Workshop
MEAN Stack WeNode Barcelona WorkshopMEAN Stack WeNode Barcelona Workshop
MEAN Stack WeNode Barcelona WorkshopValeri Karpov
 
MongoDB Israel June Meetup
MongoDB Israel June MeetupMongoDB Israel June Meetup
MongoDB Israel June MeetupValeri Karpov
 
JS-IL: Getting MEAN in 1 Hour
JS-IL: Getting MEAN in 1 HourJS-IL: Getting MEAN in 1 Hour
JS-IL: Getting MEAN in 1 HourValeri Karpov
 
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and BeyondJS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and BeyondValeri Karpov
 
MEAN Stack Workshop at Node Philly, 4/9/14
MEAN Stack Workshop at Node Philly, 4/9/14MEAN Stack Workshop at Node Philly, 4/9/14
MEAN Stack Workshop at Node Philly, 4/9/14Valeri Karpov
 
MongoDB: Queries and Aggregation Framework with NBA Game Data
MongoDB: Queries and Aggregation Framework with NBA Game DataMongoDB: Queries and Aggregation Framework with NBA Game Data
MongoDB: Queries and Aggregation Framework with NBA Game DataValeri Karpov
 

More from Valeri Karpov (20)

A Practical Introduction to GeoJSON
A Practical Introduction to GeoJSONA Practical Introduction to GeoJSON
A Practical Introduction to GeoJSON
 
A Practical Introduction to Functions-as-a-Service
A Practical Introduction to Functions-as-a-ServiceA Practical Introduction to Functions-as-a-Service
A Practical Introduction to Functions-as-a-Service
 
A Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-ServiceA Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-Service
 
Introducing Async/Await
Introducing Async/AwaitIntroducing Async/Await
Introducing Async/Await
 
Mastering Async/Await in JavaScript
Mastering Async/Await in JavaScriptMastering Async/Await in JavaScript
Mastering Async/Await in JavaScript
 
React, Redux, and Archetype
React, Redux, and ArchetypeReact, Redux, and Archetype
React, Redux, and Archetype
 
TDD a REST API With Node.js and MongoDB
TDD a REST API With Node.js and MongoDBTDD a REST API With Node.js and MongoDB
TDD a REST API With Node.js and MongoDB
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS Limitations
 
MongoDB MEAN Stack Webinar October 7, 2015
MongoDB MEAN Stack Webinar October 7, 2015MongoDB MEAN Stack Webinar October 7, 2015
MongoDB MEAN Stack Webinar October 7, 2015
 
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
 
Lessons in Open Source from the MongooseJS ODM
Lessons in Open Source from the MongooseJS ODMLessons in Open Source from the MongooseJS ODM
Lessons in Open Source from the MongooseJS ODM
 
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
 
MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
MongoDB Miami Meetup 1/26/15: Introduction to WiredTigerMongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
 
MongoDB API Talk @ HackPrinceton
MongoDB API Talk @ HackPrincetonMongoDB API Talk @ HackPrinceton
MongoDB API Talk @ HackPrinceton
 
MEAN Stack WeNode Barcelona Workshop
MEAN Stack WeNode Barcelona WorkshopMEAN Stack WeNode Barcelona Workshop
MEAN Stack WeNode Barcelona Workshop
 
MongoDB Israel June Meetup
MongoDB Israel June MeetupMongoDB Israel June Meetup
MongoDB Israel June Meetup
 
JS-IL: Getting MEAN in 1 Hour
JS-IL: Getting MEAN in 1 HourJS-IL: Getting MEAN in 1 Hour
JS-IL: Getting MEAN in 1 Hour
 
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and BeyondJS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
 
MEAN Stack Workshop at Node Philly, 4/9/14
MEAN Stack Workshop at Node Philly, 4/9/14MEAN Stack Workshop at Node Philly, 4/9/14
MEAN Stack Workshop at Node Philly, 4/9/14
 
MongoDB: Queries and Aggregation Framework with NBA Game Data
MongoDB: Queries and Aggregation Framework with NBA Game DataMongoDB: Queries and Aggregation Framework with NBA Game Data
MongoDB: Queries and Aggregation Framework with NBA Game Data
 

Recently uploaded

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Recently uploaded (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

TAO and the Essence of Modern JavaScript

  • 1. TAO and the Essence of Modern JavaScript Valeri Karpov June 21, 2018 JavaScript Zagreb #42
  • 2. About Me ● Maintainer of Mongoose (#72 on npm-rank) ● Lead Backend Engineer @ Booster ● Blogger, thecodebarbarian.com
  • 3. What This Talk is About ● Redux, MobX, ngrx, etc. are the same thing ● They’re fundamentally different from MVC ● What does “one-way data flow” mean for API devs? ● How we use TAO at Booster
  • 4. Principles of Modern State Management ● Type: data is represented by plain objects (POJO) ● Actions: function calls are represented by POJOs ● Observables: stream of all actions in the system ● TAO: Type-action-observable, as opposed to MVC
  • 5. Part 1: TAO vs MVC ● Model: data notifies controller of changes ● Controller: changes model, listens to changes ● View: DOM state
  • 6. The Problem with MVC in JS ● When did something change and how?
  • 7. With Immutable POJOs, Diffing is Easy ● Assume all changes went through `=` operator ● Objects are serializable and diffing is easy
  • 8. T is for “Type” ● Data is a POJO (or Immutable.js) ● Data is serializable ● Data is not “hydrated”: Mongoose, Ember, Vue 1.x ● Think “store” in Redux, ngrx, or MobX
  • 9. Notifying of Changes is Hard ● Proxies, Object.defineProperty() are not POJOs ● Need to “hydrate” object to get change tracking ● RIP Object.observe(), 2011-2015
  • 10. A is for “Action” ● All changes are represented by an object ● A Redux action is an object representing a fn call
  • 11. But How Do You Watch for Changes? ● Object representation of function call is useful: ○ Debugging ○ Logging ○ “Time Travelling Debugger” ● But how does this help with change tracking?
  • 12. O is for “Observable” ● Doesn’t necessarily need to be an observable ● Anything that lets you see all actions: ○ Node.js stream or event emitter ○ Redux middleware ○ ngrx effects
  • 13. Redux from the TAO Perspective ● Type: State, store.getState() ● Action: Redux actions, store.dispatch() ● Observable: middleware, reducer, React view
  • 14. ngrx from the TAO Perspective ● Type: State from @ngrx/store ● Action: Actions, store.dispatch() ● Observable: Observables, Effects @ngrx/effects
  • 15. Vuex from the TAO Perspective ● Type: State ● Action: Actions ● Observable: Mutations, views
  • 16. Part 2: Server Dev ● Do APIs really need change tracking? ● MVC is painful for REST APIs ● V in MVC = JSON object?
  • 17. Change Tracking for APIs ● API calls are short-lived ● Browser app lives for a long time, lot of actions ● The “store” is the database
  • 18. Change Tracking for APIs ● Mongoose, SQL ORMs track changes on objects ● Convert language operations to DB operations
  • 19. TAO for API Devs ● Type: data coming into the system ● Action: object representation of fn call ● Observable: see all actions in the system
  • 20. TAO for API Devs ● Can’t validate entire “state”, databases are huge ● Can validate data coming in ● Each action can define what data is valid ● Archetype: data validation lib
  • 21. TAO for API Devs ● One API call is usually one action ● Object representation for logging ● Pro tip: request ids ● Convert curl =>
  • 22. TAO for API Devs ● Actions read/write from db, but don’t do everything ● Logging, error handling, slack notifications, etc. ● “Cross-cutting concerns” ● Aspect oriented programming
  • 23. Part 3: TAO at Booster ● We’ve open-sourced archetype and tao-js on npm Archetype TAO.js
  • 24. Part 3: TAO at Booster ● A type is a constructor that throws if casting fails
  • 25. Part 3: TAO at Booster ● An action is a function, it validates data using types
  • 26. Part 3: TAO at Booster ● Middleware (locking, error handling)
  • 27. Part 3: TAO at Booster ● Homebaked observable lib, because of RxJS issues ● Triggers: like middleware, but reactive
  • 28. What’s Wrong with RxJS? ● Observable = multi-value, single error ● Uncaught error in map() => dead, silent failures
  • 29. Further Reading ● TAO examples: github.com/vkarpov15/tao ● TAO API docs: bit.ly/tao-api-docs ● Archetype: github.com/boosterfuels/archetype ● Archetype on Twitter: twitter.com/archetype_js
  • 30. Thanks For Listening! Slides on Twitter, @code_barbarian