3 ms·
In this model, the view doesn't "own" the name. The application state owns it. Think of it as being similar to the classic one request at a time LAMP app. You
by jasonwatkinspdx 12y ago
In this model, the view doesn't "own" the name. The application state owns it.
Think of it as being similar to the classic one request at a time LAMP app. You query data from the database, then a template turns that into displayed content. When you want to change the data, you send an update transaction and then redo the query and the rendering to html.
It's just as simple here. The application state is like our database. We don't change it in part, down in some particular object, we write transaction functions that take the entire state to a new state. What's neat is our code is conceptually very simple: just functions that take take state as input and render a view. It might seem this would be absurdly slow, but the implementation doesn't have to be so naive. React does diffing under the hood to figure out the exact minimum changes needed to update the DOM after the state changes. Mori gives you similar optimizations when changing the state itself.
- antihero 12y agoOk, so I guess what I'm looking for here is how to implement our "database" as a client side data model that can do its thing, with the immutable structures (mori?) so that React can figure out what's updated super quickly, and a way to make sure the app knows that it's been updated. I need examples, basically! Ideally I'd have an API to my datastore, which in turn would handle telling React what I've updated. It feels like I'm just not "getting" something with Mori. Say our state looks like this in a normal JS structure: appState = { widgets: [{name: 'blah', data: {'text': 'hello', articles: [{}]}}, ...}], pageTitle: 'Hi!', user: {name: 'Derp'}, notifications: 5 }; How would I even represent that with Mori? Say I got a push from the server that I had 6 notifications, how would I change the state to represent this? Say I wanted the widget to do an API call to update it's articles, and add any new article data to that. How would I do this?