balderdashy / mast

UI conventions built on top of Backbone.JS
MIT License
81 stars 14 forks source link

Implement support for computed properties (instead of marshalling) #45

Closed mikermcneil closed 11 years ago

mikermcneil commented 12 years ago

See http://kilon.org/blog/2012/02/backbone-calculated-fields/

mikermcneil commented 12 years ago

Schema Mapping / Marshaling / Serialization

In the same way that the goal of the APIService or server-side JSON views is to convert the raw database schema to the outward facing API format (and vice versa), the primary goal of virtual fields is converting from the server-sent API schema to the UI state model (and vice versa).

The primary goal of bindings is to convert a state change in the client-side model to the proper elements in the DOM, and to convert

Virtual fields

Bindings

The analog at the view layer is bindings: -Getter: Example: Getting the username actually selects the username input form field from the DOM and grabs its value to offer up as a client-only piece of state -Setter: Example: Setting the padding actually looks at the depth of the file/directory and adjusts the left padding accordingly. Setting empty removes or adds the collapse/expand arrow as necessary.

Summary

Data flow

Shared, Persistent Database Schema <-----> UI-Agnostic Transport Schema (REST) <-----> UI-Specific Presentation Schema

Example

UPDATE NotificationSetting SET email=TRUE WHERE AccountId=7; <-----> NotificationSetting.findAndUpdate({where:{AccountId: 7}}, {email: true}); <-----> { id: 7 notificationsEnabled: true } <----->

``` UINotificationSwitch.model.attributes.notificationsEnabled virtualField set: UINotificationSwitch.set('notificationSwitchOn') virtualField get: UINotificationSwitch.get('notificationSwitchOn') <----->

binding get: return $(".notification-switch").val() binding set: $(".notification-switch").val(this.notificationsSwitchOn) <input type='checkbox' class='notification-switch' selected='selected' />

mikermcneil commented 12 years ago

@ghernandez345 The getters UI model bindings ties into what you're working on (specifically getting the value of DOM form/input elements and stuffing them in the model)

Thoughts, feedback?

mikermcneil commented 12 years ago

State transfer encoding:

DOM
Bindings
<------- Virtual fields, subscriptions
-------> Backbone.sync

<------- APIService and/or JSON views
-------> Parameter preprocessor and error checker 
ORM interface (MATE)
DB
SQL --> MATE ---------> APIService or JSON views ---------> <---------- Virtual fields <----------- Bindings <--- DOM

APIs

       DAO  ----->  MongoAPI   ---------------------------->   REST API    <-------------  Backbone.Model  <----- jQuery
mikermcneil commented 11 years ago

Computed attributes would be nice to have-- most of the other things can be ignored