Sledom
Why should you have to commit to one MVC framework for your app? Haven't we all learned that being modular is better? React has broken out the V. This is the M.
Features
- field normalization
- field types, automatic conversion
- enum fields
- default field values
- computed fields
- validation
- dirty state
- event binding
Quick Start
Define a Model
var sledom = ;var Person = sledom;
Create an Instance
var dude = name: 'Lebowski' eyeColor: 'blue' age: 42;
Use the Instance
// Listen for changes.dude; // Set values.dude; // logs { age: 43 } // Get values.dude; // { name: 'Lebowski', eyeColor: 'blue', age: 43 }
Now that's just the beginning. Keep scrolling for more.
Sledom is in active development, so your feedback and questions are appreciated. https://github.com/reergymerej/sledom/issues
Definition
var sledom = ; var Foo = sledom; var foo = name: 'asdf' bar: 99 ;
Getting Field Values
foo; // { name: 'asdf', bar: 99, baz: true }foo; // 99fooid; // 'asdf'
Setting Field Values
fooid'new id';fooid; // 'new id' foo;foo; // 123 foofoo; // { name: 'dude', bar: 3.14, baz: false }
Computed Fields
var Foo = models; var foo = firstName: 'Jeremy' lastName: 'Greer' ; foo; // 'Jeremy Greer'
ENUM Fields
var Foo = models; var foo = ; foo; // 'red'foo; // throws error
Validation
var Foo = models; var foo = ;foo; // false foo = num: 4 ;foo; // true
Observing Changes
foo; foo;foo; // won't fire handler because nothing changed
Check Dirty State
foo = name: 'a foo' bar: 66 ;foo; // undefined foo;foo; // { name: 'new name' } foo;foo; // { name: 'new name', bar: 77 }
Instance Methods
var Foo = app; var foo = number: 999 ;foo; // 'The number is 999'
Custom Field Types
{}Fooprototype { return 'I am a Foo.';}; var Model = sledom; var model = ; model; // 'I am a Foo.'
Nested Models
var Person = sledom; var Child = sledom; var dad = name: 'Dad' gender: 'male' ;var daughter = name: 'Daughter' parent: dad ; daughter instanceof Person; // true
================================================
Please create an issue for feature requests or to report bugs.
Coming Soon
- save routines
- shorthand definitions
- model inheritence