A JavaScript application framework to promote decoupled event-driven systems and simple composite views.
TrussJs has no dependencices other than Almond, which is built into the distributed Truss.js and Truss-min.js, so you can drop either one into your project and start using TrussJS immediately.
However, if you want to make changes to the source code, you'll need to run the tests. To do so, install the devDependencies with npm install
, which will add grunt and grunt-contrib-jasmine. Use grunt test
or just grunt jasmine
to run them without jshint.
Please note, TrussJS uses Grunt 0.4.0, which is not supported on versions of Node less than 0.8.
There are three Function constructors you can build from, each of which lives in the Truss namespace;
- Truss.View
- Truss.Collection and,
- Truss.Model
Each is extended from Truss.Base and has a prototype chain to the events module.
To build a new constructor from any of these Functions, use the static construct function.
var MyConstructor = Truss.View.construct({
myProperty: 'property',
myMethod: function () {}
});
To instantiate the constructor, simply invoke its create function. There's no new
keyword here.
var myInstance = MyConstructor.create({myOptions: 'anOption'});
Or if you prefer, create a new constructor Function.
var AnotherConstructor = MyConstructor.construct({
anotherMethod: function () {}
});
If you pass a 'start' function to construct, it will be invoked when the new constructor is instantiated with create. Any options will be added to the instance and passed as an argument to the 'start' function.
AnotherConstructor = MyConstructor.construct({
start: function () {},
anotherMethod: function () {}
});
The options argument is passed into AnotherConstructor.prototype.start.
var anotherInstance = AnotherConstructor.create({myOptions: 'anOption'});