Simple, stateful, observable objects in JavaScript. Yet another model library, but this one aims to make the API experience as close to plain JavaScript objects as possible.
var User = Ento()
.attr('id', Number)
.attr('firstName')
.attr('lastName');
me = new User({ firstName: 'John', lastName: 'Coltrane' });
me.firstName = 'Jacques';
me.first_name;
m.on('change', function (attrs) { ... });
-
Plain attributes: ECMAScript getters and setters are used to listen for updates in attributes. No need for methods like .get() and .set().
-
Change tracking: Listen for changes in instances via
.on('change')
. -
Custom sync: No persistence is built in (AJAX, SQL, etc). Implement it however you need it.
-
Model states: Keeps track of your model's state if it's fetching, or got an error. This is useful when used with data-binding view libraries.
-
Browser or Node.js: Reuse the same business code in your client-side libs and your server-side libs.
"Ento" is the Esperanto transation of the word "entity."
Ento depends on underscore.js, and is available via Bower and NPM.
See documentation for better instructions.
Computed properties: you can define properties that are derived from other properties.
var Person = Ento()
.attr('firstName')
.attr('lastName')
.attr('fullName', ['firstName', 'lastName'], function () {
return [this.firstName, this.lastName].join(' ');
});
var me = new User({ firstName: "Miles", lastName: "Davis" });
me.fullName;
=> "Miles Davis"
Plugins, and instance methods: create methods via use()
.
var Car = Ento()
.use(Ento.persistence) // plugins
.use(Ento.validation)
.use({
start: function () { ... },
drive: function () { ... }
});
var civic = new Car();
civic.start();
See the documentation for even more features.
- It's like Ember.Object, except decoupled from any MVC library.
- It's like Backbone.Model, but less emphasis on collections.
- It's like Spine.Model, but with change tracking.
- It's like Modella, but with collections. (You should probably try Modella, actually.)
- It's like all of the above, with simpler syntax, and a use-only-what-you-need approach.
Contains code from Backbone.js.
Backbone's MIT license goes here
Ento © 2014+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors.
ricostacruz.com · GitHub @rstacruz · Twitter @rstacruz