You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🤔 I wonder if we can combine a couple things used in the "controller" layer to make a useful UI model. This would be a wrapper around Baobab that makes it easy to use server/client among other useful wrappings.
Wraps up Lokka + convenience methods for query/mutate + update state
Built in bootstrapping data from server/client
Built in debugger/time-travel UI for dev
Built in persiting state to local storage/error-reporting
Easy way to attach to React tree or routing context
Middleware everywhere
What about the routing/controller layer being entirely a stack of koa-like middleware. For instance ctx is an object that morphs shape and tries to consolidate common abstractions. e.g. First it contains Koa server ctx stuff, then it contains Page.js ctx stuff, then any further client-side events carry that ctx and other relevant stuff like ctx.event. This could provide an easy solution for sharing things necessary across interaction e.g the state tree or cookies. It could also allow for elegant middleware that applies to all interactions such as adding a single middleware to centralize analytics tracking or authorization.
Take this concept to the extreme and you could imagine the entire application lifecycle as a bunch of middleware with routes. For instance "saving an artwork" could look like...
I guess you couldn't reasonably share ctx b/t app and api here, but potentially app server-side ctx could be partially shared to the client, then shared across the rest of client-side interactions.
This idea of a universal controller middleware stack could allow for a powerful low level abstraction that can be built upon to provide universal routing, analytics, rendering, and more.
consttrack=(ctx,next)=>{awaitnext()if(ctx.url&&!ctx.browser)analytics.track(`Loading page ${ctx.url}`)elseif(ctx.url)analytics.track(`Loaded page ${ctx.url}`)elseif(ctx.event)analytics.track(`Clicked ${event.target.className}`)}constindex=async({ state, render })=>{const{ todos }=awaitapi.query(`{ todos { _id body } }`)state.set({ todos })render(Body)}constremoveTodo=async({ api, _id })=>{awaitapi.mutate(`{ deleteTodo(_id: "${_id}") { _id } }`)consttodos=reject(state.get('todos'),{ _id })state.set({ todos })}constaddTodo=async({ event, api, state },next)=>{if(event.key!=='Enter')returnnext()const{createTodo: todo}=awaitapi.mutate(`{ createTodo(body: "${event.target.value}") { _id body } }`)state.select('todos').push(todo)}controller.use(track)controller.get('/',index)controller.on('removeTodo',removeTodo)controller.on('addTodo',addTodo)
Ui-Model
🤔 I wonder if we can combine a couple things used in the "controller" layer to make a useful UI model. This would be a wrapper around Baobab that makes it easy to use server/client among other useful wrappings.
Middleware everywhere
What about the routing/controller layer being entirely a stack of koa-like middleware. For instance
ctx
is an object that morphs shape and tries to consolidate common abstractions. e.g. First it contains Koa server ctx stuff, then it contains Page.js ctx stuff, then any further client-side events carry that ctx and other relevant stuff like ctx.event. This could provide an easy solution for sharing things necessary across interaction e.g thestate
tree or cookies. It could also allow for elegant middleware that applies to all interactions such as adding a single middleware to centralize analytics tracking or authorization.Take this concept to the extreme and you could imagine the entire application lifecycle as a bunch of middleware with routes. For instance "saving an artwork" could look like...
I guess you couldn't reasonably share
ctx
b/t app and api here, but potentially app server-side ctx could be partially shared to the client, then shared across the rest of client-side interactions.This idea of a universal controller middleware stack could allow for a powerful low level abstraction that can be built upon to provide universal routing, analytics, rendering, and more.
View
Router
Controller
Model
The text was updated successfully, but these errors were encountered: