mvc 2.0 - a breakthrough

44
MVC 2.0 A Breakthrough

Upload: constantin-dumitrescu

Post on 12-Apr-2017

187 views

Category:

Internet


0 download

TRANSCRIPT

Page 1: MVC 2.0 - A Breakthrough

MVC 2.0

A Breakthrough

Page 2: MVC 2.0 - A Breakthrough
Page 3: MVC 2.0 - A Breakthrough

Part 1. The Facts (The MVC History)

Page 4: MVC 2.0 - A Breakthrough

MVC diagram (first draft in 1978)

1979 - Models - Views - Controllers by Trygve Reenskaug

Page 5: MVC 2.0 - A Breakthrough

What’s a Thing in Thing-Model-View-Editor?

“Something that is of interest to the user …. like a house or an integrated circuit ….

like a new idea or opinions about a paper or like a computer …. like a circuit

element.”

Page 6: MVC 2.0 - A Breakthrough

Poor Analogies

Page 7: MVC 2.0 - A Breakthrough

MVC Diagram (second draft 1988)

Page 8: MVC 2.0 - A Breakthrough

Which is which?

Page 9: MVC 2.0 - A Breakthrough

Part 2. Dispelling the Advertised Benefits

Page 10: MVC 2.0 - A Breakthrough

Interwoven Boundaries = No Real Separation of Concerns

Page 11: MVC 2.0 - A Breakthrough

Redundant Processing / Handling / Storing = Duplication

Page 12: MVC 2.0 - A Breakthrough

Data Handling Everywhere = Inconsistency & Madness

Page 13: MVC 2.0 - A Breakthrough

No Autonomy

Page 14: MVC 2.0 - A Breakthrough

MVC + OOP = Reusability is Futile

Page 15: MVC 2.0 - A Breakthrough

Linear Design Pattern = No Parallel Development

Page 16: MVC 2.0 - A Breakthrough

A simple example

Page 17: MVC 2.0 - A Breakthrough

Part 3. A New Postulate for MVC

Page 18: MVC 2.0 - A Breakthrough

Demands from Real-Time Data

1. High Velocity Views (>100 times / s)2. Building Ad-Hoc Views3. Minimal data processing & conversion4. High Stability5. No Corrosion 6. Push & Pull compatible7. Intelligent Caching8. Multiprocess / Multithreaded by default9. Complete System Predictability10. Engineered to be Streamlined

Page 19: MVC 2.0 - A Breakthrough

Demands from Microservices

1. Truly Decoupled Components2. A Universal & Coherent Way to Accessing / Modeling /

Sharing Data3. Small footprint4. Frictionless Parallelization5. Testability6. Decentralized Governance7. Simple Database Segregation8. Simple Infrastructure Automation9. Fault Tolerant & Antifragility

Page 20: MVC 2.0 - A Breakthrough

Demands from Reactive Systems

1. Simply express dynamic data2. Asynchronous & Concurrent by default3. Never store data in code4. Pure & Streamlined processing5. Modeling Time and Data together6. Responding to events in a predictable fashion7. Clear entry and exit points

Page 21: MVC 2.0 - A Breakthrough

Part 4. Quick Prep-up Before MVC 2.0

Page 22: MVC 2.0 - A Breakthrough

Essential State

Page 23: MVC 2.0 - A Breakthrough

Derived State

Page 24: MVC 2.0 - A Breakthrough
Page 25: MVC 2.0 - A Breakthrough

JSON Data & JSON Schema{ "type": "object", "properties": { "user": { "type": "object", "properties": { "name": { "type": "string" }, "email": { "type": "string", "pattern": "^\S+@\S+$" } }, "required": [ "name", "email" ] } }, "required": [ "user" ]}

{ "user": { "name": "John Doe", "email": "[email protected]" }}

Page 26: MVC 2.0 - A Breakthrough

... YAML works too!type: object,properties: user: type: object properties: name: type: string email: type: string, pattern: “^\S+@\S+$" required: - name - emailrequired - user

user: name: John Doe email: [email protected]

Page 27: MVC 2.0 - A Breakthrough

JSON Patch & JSON Pointer

[ {"op": "replace", "path": "/user/name", "value": "Jane Roe"}, {"op": "add", "path": "/user/address", "value": "51 Street"}, {"op": "test", "path": "/user/id", "value": 23}]

{ "user": { "name": "John Doe", "id": 23 } }

{ "user": { "name": "Jane Roe", "address": "51 Street", "id": 23 } }

Page 28: MVC 2.0 - A Breakthrough

A simple JSON Pointer

"/bam": node(["/foo/bar/baz"], cb)

Page 29: MVC 2.0 - A Breakthrough

Let’s work on some examples #1

foo: 123

// get('/foo') -> '123'

Page 30: MVC 2.0 - A Breakthrough

#2

foo: 123bar: node(['/foo'], function (data) { return data})

// get('/foo') -> '123'// get('/bar') -> '123'

Page 31: MVC 2.0 - A Breakthrough

#3

name: Foosurname: BarfullName: node(['/surname', '/name'], function(surname, name) { return surname + name})

// get('/fullName') -> ‘Bar Foo'

Page 32: MVC 2.0 - A Breakthrough

#3 - continueduser: name: Foo surname: Bar fullName: node(['/user/surname', '/user/name'], function(surname, name) { return surname + name })

// get('/user/fullName') -> ‘Bar Foo'

Page 33: MVC 2.0 - A Breakthrough

#4session: token: xyz createdAt: 1467199000000 expiresIn: 60000currentTime: 146720000000

// get('/session/isValid') -> false

Page 34: MVC 2.0 - A Breakthrough

#4 - continuedsession: { token: xyz createdAt: 1467199000000 expiresIn: 60000 isValid: node(['/session/createdAt', '/session/expiresIn', '/currentTime'], function (createdAt, expiresIn, now) { return createdAt + expiresIn > now })currentTime: 146720000000// get('/session/isValid') -> false

Page 35: MVC 2.0 - A Breakthrough

#5 ajax: createdAt: 1467199000000 sentAt: 1467199000100 timeoutAfter: 60000 method: POST url: http://foo.bar data: sample: baz receivedAt: nullcurrentTime: 1467200000// get('/ajax/isPending) -> true

Page 36: MVC 2.0 - A Breakthrough

#5 - continued

ajax: ... isPending: node(['/ajax/sentAt', '/ajax/timeoutAfter', '/ajax/receivedAt', '/currentTime'], function (sentAt, timeout, receivedAt, now) { return receivedAt === null && sentAt + timeout < now })currentTime: 1467200000

// get('/ajax/isPending) -> true

Page 37: MVC 2.0 - A Breakthrough

Part 5. MVC 2.0

Page 38: MVC 2.0 - A Breakthrough
Page 39: MVC 2.0 - A Breakthrough

View

Role. Outputs data in a certain format

Purpose. Gives meaning to data by exporting it to the world

Notes. The only true essential component. An application can work just fine with only a View component and a Data Tree.

Name. Through it the World views the data, sees what it needs to see in a manner suitable to the World - hence the name View.

Page 40: MVC 2.0 - A Breakthrough

Controller

Role. Inputs data in the JSON patch format (essential data)

Purpose. Creating movement / momentum / triggers transformations / etc

Notes. All actions are correlated to existing data or lack of data. Every action is traceable from an initial state.

Name. It exerts control over what data is added / replaced and controls the outside world - hence the name Controller.

Page 41: MVC 2.0 - A Breakthrough

Model

Role. Combines and derives data

Purpose. From simple / uninteresting data it creates sophisticated / complex representations

Notes. All “if statements” are data. Derived data is never stored / only cached. Models define the diversity of data.

Name. Treats data as a maleable material and shapes it in new and interesting forms. It Models it.

Page 43: MVC 2.0 - A Breakthrough

References

https://www.kilim.com/images/content/kilim_weaving_technique_9.jpghttp://karinsebelin.com/wp-content/uploads/2015/10/Marionette-Abh%C3%A4ngigleit.jpghttp://pre03.deviantart.net/3a90/th/pre/f/2013/205/6/e/crowded_beach_by_samiatay-d6ew2um.jpghttp://media.istockphoto.com/photos/square-peg-in-a-round-hole-picture-id173230047?k=6&m=173230047&s=170667a&w=0&h=vrjQtexdKNNX_bTF27tyJwiAOKM-kWIhySBWSa2gzcM=http://worldartsme.com/images/cartoon-person-taking-clipart-1.jpghttp://images.clipartpanda.com/box-clipart-aie7gkzi4.pnghttp://previews.123rf.com/images/gnurf/gnurf1106/gnurf110600003/9926108-Confused-cartoon-guy-scratching-his-head-Stock-Vector.jpghttp://www.clipartkid.com/images/243/small-house-icon-png-clipart-image-iconbug-com-8VpCSX-clipart.pnghttp://sr.photos1.fotosearch.com/bthumb/CSP/CSP990/k11301571.jpghttp://cdn.xl.thumbs.canstockphoto.com/canstock7934222.jpghttp://www.collaborationobjects.com/wp-content/uploads/2015/01/Great_Alaskan_Lumberjack_Show_crosscut_saw.jpghttp://webframeworks.kr/tutorials/react/imgs/complex_mvc.png

Page 44: MVC 2.0 - A Breakthrough

Thank you!

Constantin Dumitrescu, find me as @dumconstantin on

Ask me about: JS, FP, Docker, Automating things, Development Tools, Radical Management

Presentations:

The Philosophy and Practice of the Pure Function / The JSON Architecture 1 & 2 / RamdaJS - An Epic Tale