PIMPLE.JS
Pimple is a Dependency injection container for javascript , compatible with all javascript enabled browsers.
see : http://en.wikipedia.org/wiki/Dependency_injection
author M.Paraiso , inspired by Pimple by Fabien Potencier : https://github.com/fabpot/Pimple
contact: mparaiso@free.Fr
status: beta
features:
- AMD compatible
change log
- 0.0.4 pimple can now be instanciated without new
- 0.0.3 api changed for shared,protected and extended services , see README.md
- 0.0.2 register method added
USAGE
installation
in a html file
with nodejs
//npm install -g pimple var pimple = ;
definition
var pimple =
or initialise the container with values
var pimple = {return "hi"}'color':'green'
define a service
you define a service with an anonymous function
// Pimple.set(name,callback)// given a Database objectpimple; // in recent browsers , you can use accessors ( IE9+,CHROME,FIREFOX,OPERA,SAFARI )pimple;
define a paramater
// just set a scalar valuepimple;
query for a service
since the service is wrapped into a function , it will be lazy-loaded , allowing to save computer CPU.
pimple//or on recent browsers support defineProperty ( IE9+,CHROME,FIREFOX,OPERA,SAFARI )pimpleservicepimple'service'
define a shared service
the service callback with be exectuted only once and the result will be shared for each call
// Pimple.share(callback)pimple
define a protected service
//Pimple.protect(function)pimple;pimple; // alerts Hi
extends a defined service
Pimple.extend returns a service definition ( a callback ).
// define a service ajax_servicepimple;//Pimple.extend(existing_service_name,callback)pimple;
get the service raw definition
Pimple.raw returns the original service defintion ( a scalar or a callback )
pimple//Pimple.raw(service_name)pimple // return the service callback definition