Have ideas to improve npm?Join in the discussion! ¬Ľ

    ento

    0.0.1¬†‚Äʬ†Public¬†‚Äʬ†Published

    ento.js

    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."

    Status

    API overview

    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.

    What's it like?

    • 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.

    Acknowledgements

    Contains code from Backbone.js.

    Backbone's MIT license goes here

    Keywords

    none

    Install

    npm i ento

    DownloadsWeekly Downloads

    1

    Version

    0.0.1

    License

    MIT

    Last publish

    Collaborators

    • avatar