Skip to content

Commit

Permalink
SpredfastLegacy#1 update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
iamnoah committed Mar 19, 2012
1 parent 2e7a8bc commit b99f7a1
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions README.md
Expand Up @@ -31,7 +31,7 @@ In the examples, we name the injector variable `injector`, but you can call it w


## Injecting plain functions ## Injecting plain functions


var injector = inject({ var injector = Inject({
name: 'foo', name: 'foo',
factory: function() { factory: function() {
// your factory function can do anything. if you need to make ajax calls or use // your factory function can do anything. if you need to make ajax calls or use
Expand All @@ -53,7 +53,7 @@ Notice that the names passed to injector have to match the name of the factory.


What if you don't know the names of the factory you want injected or the names vary? What if you don't know the names of the factory you want injected or the names vary?


var injector = inject({ var injector = Inject({
name: 'bar', name: 'bar',
factory: function() { factory: function() {
// your factory function can do anything. if you need to make ajax calls or use // your factory function can do anything. if you need to make ajax calls or use
Expand Down Expand Up @@ -93,7 +93,7 @@ that can use whatever injector context it happens to be called in.


### Using the current context ### Using the current context


alertFoo: inject.require('foo',function(foo) { alertFoo: Inject.require('foo',function(foo) {
alert(foo); alert(foo);
}) })


Expand All @@ -102,13 +102,13 @@ that can use whatever injector context it happens to be called in.
### Setting/changing the context ### Setting/changing the context


Calling an injected function sets the context while that funcion is executing, Calling an injected function sets the context while that funcion is executing,
so any `inject.require` functions called (note: not defined) within an injected so any `Inject.require` functions called (note: not defined) within an injected
function will inherit the injector. function will inherit the injector.


var injector = inject(...); var injector = Inject(...);
injector(function() { injector(function() {
// functions like this will resolve foo from injector // functions like this will resolve foo from injector
inject.require('foo',function(foo) { Inject.require('foo',function(foo) {
// ... // ...
})(); })();
})(); })();
Expand All @@ -120,10 +120,10 @@ any injected function will serve.


Calling an injector function will set the context, but what about functions that need to be Calling an injector function will set the context, but what about functions that need to be
called outside of an injector function? If you can't use a specific injector, you called outside of an injector function? If you can't use a specific injector, you
can use `inject.useCurrent` to create a function that will reset the context to whatever can use `Inject.useCurrent` to create a function that will reset the context to whatever
context the function is declared in. context the function is declared in.


setTimeout(inject.useCurrent(function() { setTimeout(Inject.useCurrent(function() {
// do things // do things
}),500); }),500);


Expand All @@ -132,22 +132,22 @@ context the function is declared in.
### Controller Action Handlers ### Controller Action Handlers


Controllers action handlers will not generally be called inside an injected function, Controllers action handlers will not generally be called inside an injected function,
so any handler using `inject.when` has to get the injector some other way. so any handler using `Inject.when` has to get the injector some other way.
`inject.setupControllerActions` will setup the action handlers such that they `Inject.setupControllerActions` will setup the action handlers such that they
use the injector context that was active when the controller was created: use the injector context that was active when the controller was created:


$.Controller('MyController',{},{ $.Controller('MyController',{},{
setup: inject.setupControllerActions setup: Inject.setupControllerActions
// OR // OR
setup: function() { setup: function() {
// controllerSetup will call this._super // controllerSetup will call this._super
inject.setupControllerActions.apply(this,arguments); Inject.setupControllerActions.apply(this,arguments);
// do other setup stuff // do other setup stuff
} }
}); });


var injector1 = inject(...); var injector1 = Inject(...);
var injector2 = inject(...); var injector2 = Inject(...);


injector1('foo',function() { injector1('foo',function() {
// all action handlers will use injector1 // all action handlers will use injector1
Expand All @@ -159,5 +159,5 @@ use the injector context that was active when the controller was created:
}); });


Under the hood, all `setupControllerActions` is doing is wrapping each action with Under the hood, all `setupControllerActions` is doing is wrapping each action with
`inject.useCurrent`. `Inject.useCurrent`.


0 comments on commit b99f7a1

Please sign in to comment.