Convention-over-configuration framework for Backbone.js
The productivity-enhancing front-end library for Sails. Mast was built from the ground up for creating realtime web applications that work with handsets, tablets, and PC browers. Like Sails, Mast is a collection of the latest stable versions of really great libraries, in this case Backbone.js, jQuery, and Socket.io.
With Mast, building the front-end for your app is faster, 'funner' and requires fewer lines of code.
// This Collection is synced with the serverMastregisterCollection'Leaders'url : '/leader'model :defaults: // Fields specified exclusively on the client are not sharedhighlight: falsereturn -modelget'votes';;// This Tree brings life to the leaderboard and its itemsMastregisterTree'LeaderBoard'template : '.template-leaderboard' // Identify an HTML template to represent the leaderboard framemodel :selected: nullcollection : 'Leaders' // Associate a collection with the leaderboardbranchComponent : 'LeaderBoardItem' // An instance of branchComponent will be created for each item in the collectionbranchOutlet : '.item-outlet' // A CSS selector, automatically scoped within the component, to identify where new branches should be appendedevents:'click a.add-points' : 'add5Points' // Add 5 points to the selected Leaderthiscollectionfetch;thisget'selected'increment'votes'5;thisget'selected'save;thiscollectionsort;;// This component represents a single row of the leaderboardMastregisterComponent'LeaderBoardItem'template : '.template-leaderboard-item' // Identify an HTML template to represent each leaderboard itemevents :click : 'select'// When an item is clicked on, mark it as selectedthisparentget'selected' && thisparentget'selected'set'highlight'false;thisset'highlight'true;thisparentset'selected'this;;
And here's an example of the server-side, assuming you're using Sails:
Leader = Modelextendtitle : STRINGvotes : type: INT defaultValue: 0;
Convention over configuration.
Live page updates.
At its core, Mast is made up of Components, Models, and Collections. Components are very closely related to Backbone Views, and Models and Collections are exactly like their Backbone equivalents.
Mast introduces the concept of a Component, which is a minimal logical UI element which completely abstracts DOM templating. When you change the model, or change the template, for a component, it just works-- the screen automatically gets updated.
Mast also enhances jQuery's DOM events by adding "pressEnter", "pressEscape", and "clickoutside", as well as providing access to global events, like $(window).scroll, from the events hash (no more worrying about whether the element you're binding to has focus or not!).
See the Wiki.
The Sails framework, including Mast, Rigging, and other related packages, are jointly developed and supported by Mike McNeil and Balderdash Design Co. Balderdashs build wonderful web apps as a service, and after much frustration, we built Sails to use on our customers' projects. Naturally, we open-sourced it. Hopefully, it makes your life a little bit easier!
Copyright © 2012 Mike McNeil
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.