seedhq
v0.0.25
Published
Elegant customizable inheritance, attributes and events in JavaScript.
Downloads
38
Readme
SeedHq
Introduction
Elegant customizable inheritance, attributes and events in JavaScript.
- inheritance,
Seed.extend
and the"+method"
convention help you inherit fast and easily, see Extend with Seed.js - attributes, with easy and flexible
options
keyword, see Manage attributes with 'options' - events and subscriptions, to avoid object persistance due to dirty event subscriptions see Use events
- sub, build a sub object of a parent one see What is it sub ?
Basic Usage
var S = require("SeedHq", function(r){
var S = r.Seed;
/* code */
});
Extend your own Constructors
var Fruit = S.extend({
options : {
// by default the fruit is Tasty
isTasty : true,
//and no one owns it
owner : null
},
// i like to taste any fruit
taste : function() {
console.log("I like to taste a fruit");
},
dump : function() {
return {
objectType : "a fruit"
}
}
});
var Banana = Fruit.extend({
// by default the banana is owned by a banana eater and is yellow
"+options" : {
owner : "banana eater",
color : "yellow"
},
// but the taste of the banana depends if it tasty
"+taste" : function() {
console.log(this.isTasty ? "GREAT!" : "beurk!");
},
"+dump" : function() {
return {
color : this.color
}
}
});
Instanciate them
var oldBanana = new Banana({
isTasty : false,
color : "black",
owner : "me"
});
// options are set as attributes in the instance
oldBanana.isTasty
//=> false
// +taste in Banana is executed after taste in Fruit
oldBanana.taste();
// I like to test fruits
// beurk!
var favoriteBanana = new r.Banana();
favoriteBanana.taste();
// I like to test fruits
// GREAT!
favoriteBanana.dump();
//=> { color : "yellow", objectType : "a fruit"}
More infos/usages
Seed.js is a package of 4 little Tools :
- Extendable, (in SeedHq/Extendable), extend objects protoypes gracefully with +/- convention see Extend with Seed.js
- Eventable, (in SeedHq/Eventable), emit and subscribe event properly, see Use events
- options, (in SeedHq), elegant attributes set. see Manage attributes with 'options'
- sub, (in SeedHq), elegant attributes set What is sub ?
Demo
## Install ##
SeedHq is coded as AMD module but can be installed with npm, bower or old-fashioned src=".min.js".
With npm:
npm install seedHq
and use it with nodejs:
var SeedHq = require('seedHq')
With bower:
bower install SeedHq
Point SeedHq
to [bower_components_path]/SeedHq/app/SeedHq.js
into your requirejs path config
and load it with requirejs:
require(['SeedHq/SeedHq'], function( SeedHq ){
})
With src=" .min.js"
Inside the dist
folder, download latest standalone minified version or development version and include it in your html page:
<script src="[path_to_source]/SeedHq-latest-standalone-min.js%>"></script>
The module is available via the scope
window.SeedHq
To do
- rewrite old tests with mocha
- clean hooks naming and implementation
- document hooks
## Documentation ##
See jsdoc-generated documentation in /documentation
Folder Structure
app -> development files
|- bower_components -> [bower](https://github.com/bower/bower) front-end packages
|- main.js -> main file for browser and node.js, handle AMD config
|- seed_hq -> main AMD module
test -> unit tests
|
tasks -> [Grunt](http://gruntjs.com/) tasks, see [generator-mangrove-module](https://github.com/cagosta/generator-mangrove-module)
|
dist -> distribution & build files
|
node_modules -> node packages
|
documentation -> [jsdoc](http://usejsdoc.org/about-jsdoc3.html) generated documentation
Run unit tests
On the browser
Run grunt test:browser
and open test/
on your browser.
#### On a headless browser ####
grunt test:headless
will run your tests in a headless browser, with phantomjs and mocha
On node
grunt test:node
will run your tests with node and mocha.
Because of requirejs, the mocha
command does not work.
Build your own
This project uses Node.js, Grunt and Require.js for the build process. If for some reason you need to build a custom version install Node.js, npm install
and run:
grunt build
## Yeoman Mangrove module Generator ##
This module is based on a Yeoman generator: Generator-mangrove-module
Check it for task-related references such as build, deploy etc ..