new Noder()
Noder constructor.
The Noder instance is created when the first usage of require('noder.io'),
then the same object (reference) is returned by require('noder.io') in the next usages.
// file: a.js
var noder = require('noder.io');
// true
console.log(typeof noder === 'object');
// true
console.log(noder instanceof noder.Noder);
noder.$di.set('hello', '-> Hello from a.js file.');
// file: b.js
var noder = require('noder.io');
// -> Hello from a.js file.
console.log(noder.$di.get('hello'));
See also
Classes
new Noder()
Noder constructor.
For creating a new instance of Noder.
var api = new noder.Noder();
new Collection(values)
Collection constructor.
For creating a new instance of Collection.
| Name | Type | Argument | Description |
|---|---|---|---|
| values |
object
|
optional | (Optional) values to add in the collection. |
var collection = new noder.Collection();
collection.set('keyName', 'any value');
// any value
console.log(collection.get('keyName'));
See also
Properties
-
$di :Collection
-
IOC container.
See Collection API doc.
See alsoExample
noser.$di.set('name', Nico); var hello = noder.$di.apply(function() { return 'Hello ' + this.name; });
Methods
-
createCollection(values)
-
Create a collection container.
ParametersName Type Argument Description values objectoptional Optional values to add in the new collection.
var collection = noder.createCollection({'foo': 'bar'}); // display "bar" console.log(collection.get('foo'));ExampleReturnsType Description CollectionThe new
Collectioninstancevar collection = noder.createCollection(); // true console.log(collection instanceof noder.Collection); collection.set('keyName', 'any value'); // any value console.log(collection.get('keyName'));
See also -
createNoder()
-
Create a new
Noderinstance.ExampleReturnsType Description NoderThe new
Noderinstancevar api = noder.createNoder(); // true console.log(api instanceof noder.Noder); -
use(noderPlugin, arguments)
-
Use a noder plugin. A plugin is initialized by the method
__noder().See also plugins in the guide.
ParametersName Type Argument Description noderPlugin stringobjectfunctionA noder plugin. If
noderPluginis:string: the plugin is loaded withrequireand called by passing the current instance ofnoderlikerequire(noderPlugin).__noder(noder [, optional argument, ...]);objectorfunction: the method__noder()is called by passing the current instance ofnoderlikenoderPlugin.__noder(noder [, optional argument, ...]);
arguments mixedoptional repeatable Zero, one or several arguments passed to plugin.
ThrowsType Description TypeErrorIf the plugin has not the method __noder().
ExampleReturnsType Description NoderThe current
Noderinstance.// example-plugin.js * module.exports.__noder = examplePlugin(noder, arg1, arg2) { noder.$di.set('foo', arg1 + ' and ' + arg2); return noder; }; // app.js var noder = require('noder.io').createNoder(); var examplePlugin = require('./example-plugin'); noder.use(examplePlugin, 'any value 1', 'any value 2'); // displays: 'any value 1 and any value 2' console.log(noder.$di.get('foo')); -
$invoke(deps, fn)
-
Shortcut of
noder.$di.invoke().Call a function with dependencies injection.
Unlike
noder.$invoke(), the returned value of each dependency is passed tofn.ParametersName Type Argument Description deps stringarrayfunctionSee Collection.invoke().
fn functionoptional See Collection.invoke().
ReturnsType Description mixedThe result of
fn.
See also -
$inject(deps, fn)
-
Shortcut of
noder.$di.inject().Call a function with dependencies injection.
Unlike
noder.$invoke(), the raw value of each dependency is passed tofn.ParametersName Type Argument Description deps stringarrayfunctionSee Collection.inject().
fn functionoptional See Collection.inject().
ReturnsType Description mixedThe result of
fn.
See also -
$provider(key, deps, fn)
-
Shortcut of
noder.$di.provider().Create a
providerthat supports dependencies injection. When the itemkeyis called, it calls the functionfnby passing dependenciesdeps.This method defines a function that returns the result of
noder.$di.inject(deps, fn).ParametersName Type Argument Description key stringThe key (provider identifier).
deps stringarrayfunctionSee Noder.$inject().
fn functionoptional See Noder.$inject().
ReturnsType Description NoderThe current
Noderinstance.
See also -
$factory(key, deps, fn)
-
Shortcut of
noder.$di.factory().Create a
factorythat supports dependencies injection. When the itemkeyis called, it calls the functionfnby passing dependenciesdeps.This method defines a function that returns the result of
noder.$di.invoke(deps, fn).ParametersName Type Argument Description key stringThe key (factory identifier).
deps stringarrayfunctionSee Noder.$invoke().
fn functionoptional See Noder.$invoke().
ReturnsType Description NoderThe current
Noderinstance.
See also -
$singleton(key, fn)
-
Shortcut of
noder.$di.singleton().Create a singleton (function shared).
ParametersName Type Description key stringThe key (function identifier).
fn functionThe function, executed once, after the value is returned when is again called.
ReturnsType Description NoderThe current
Noderinstance.
See also -
$apply(bindable, arguments)
-
Shortcut of
noder.$di.apply().Calls a given function by binding the scope (
this) to the$dicontainer (noder.$di._container).ParametersName Type Argument Description bindable functionobjectSee Collection.apply().
arguments mixedoptional repeatable Zero, one or more arguments passed to
bindable.ExampleReturnsType Description mixedThe value returned by
bindable.noder.$di.set('name', 'Nico'); // returns 'Nico' noder.$apply(function() { return this.name; });
See also -
$wrap(value)
-
Shortcut of
noder.$di.wrap().Wrap a value. Useful to avoid calling a function in the implementation of a provider or a factory.
ParametersName Type Description value mixedThe value to wrap.
ReturnsType Description functionvaluewrapped by a function.
See also -
$require(property, required, obj)
-
Lazy
require(), register a new lazy loadable property whose the value will be assigned on the fly withrequire()only when it is used.The property configuration is :
- enumerable: true,
- configurable: false,
- writable: false
ParametersName Type Argument Description property stringfunctionThe property name or
requiredvalue if therequiredargument is not provided (shortcut).required stringfunctionoptional The module name or the JS file path required to set the property value. Or a custom loader handler via a given function, the scope (
this) bind tonoder.$di._containerlikenoder.$apply().Note:
- The
requiredargument is passed to the functionrequire(). - The
requireditem is only loaded the first time (singleton).
obj objectoptional The object where the property is created. If is not provided, it's the current instance of
Noder.ExamplesReturnsType Description NoderThe current
Noderinstance.// Register `markdown` property // Note: `marked` module is not loaded noder.$require('markdown', 'marked'); // Now load the `marked` module in the `markdown` property noder.markdown;// Register a sub-property. noder.models = {}; noder.$require('User', './models/user', noder.models); // Load the `./models/user` module in `noder.models.User` property. noder.models.User.someMethod(); -
$require.isLoaded(property, obj)
-
Check if a given module is loaded.
ParametersName Type Argument Description property stringThe property name.
obj objectoptional Object to check the property. If is not provided, it's the current instance of
Noder.ExampleReturnsType Description booltrueif the given module is loaded,falseotherwise.noder.$require('express'); // false console.log(noder.$require.isLoaded('express')); var express = noder.express; // true console.log(noder.$require.isLoaded('express'));
See also