<commit_before># DeftJS

DeftJS is a micro-architecture that enables nimble development of enterprise class web applications with Ext JS and Sencha Touch.

# Goals

DeftJS enhances Ext JS and Sencha Touch's APIs with patterns and best practices discovered by top RIA developers at some of the best consulting firms in the industry.

DeftJS provides:

* **Simplicity**
	* Eliminates boilerplate code in favor of the simplest expression of developer intent.
* **Approachability**
	* Builds on familiar Ext JS API syntax conventions for 'pay-as-you-go' complexity.
* **Flexibility**
	* Coordinates dynamic assembly of object dependencies based on a configurable IoC container.
* **Reusability**
	* Enables business layer code reuse between Ext JS and Sencha Touch applications.
* **Testability**
	* Promotes loose coupling through class annotation driven dependency injection.

DeftJS provides the building blocks for scaling up to meet the needs of large enterprise class applications and development teams.

# Features

* **IoC Container**
	* Provides class annotation driven dependency injection.
	* Maps dependencies by user-defined identifiers.
	* Resolves dependencies by class instance, factory function or value.
	* Supports singleton and prototype resolution of class instance and factory function dependencies.
	* Offers eager and lazy instantiation of dependencies.
	* Injects dependencies into Ext JS class configs and properties before the class constructor is executed.

# API

## Deft.ioc.Injector

A lightweight IoC container for dependency injection.

### Configuration

**Classes**

In the simplest scenario, the Injector can be configured to map identifiers by class names:

	Deft.Injector.configure([
		contactStore: 'MyApp.store.ContactStore',
		contactManager: 'MyApp.manager.ContactManager',
		...
	]);

When the Injector is called to resolve dependencies for these identifiers, a singleton instance of the specified class will be created and returned.

Where necessary, you can also specify constructor parameters:

	Deft.Injector.configure({
		contactStore: {
			className: 'MyApp.store.ContactStore',
			parameters: [{
				proxy: {
					type: 'ajax',
					url: '/contacts.json',
					reader: {
						type: 'json',
						root: 'contacts'
					}
				}
			}]
		},
		contactManager: 'MyApp.manager.ContactManager',
		...
	});

You can also specify whether a class is instantiated as a singleton (the default) or a prototype:

	Deft.Injector.configure({
		contactController: {
			className: 'MyApp.controller.ContactViewController',
			singleton: false
		},
		...
	});

Additionally, you can configure dependency providers to be eagerly or lazily (the default) instantiated:

	Deft.Injector.configure({
		preferences:  {
			preferences: 'MyApp.preferences.Preferences',
			eager: true
		},
		...
	});

When a dependency provider is configured for eager instantiation, it will be created and cached in the Injector immediately after all the identifiers in that `configure()` call have been processed.

*NOTE:* Only singletons can be eagerly instantiated.

**Factory Functions**

The Injector can also be configured to map identifiers to factory functions:

	Deft.Injector.configure({
		contactStore: {
			fn: function() {
				if ( useMocks ) {
					return Ext.create( 'MyApp.mock.store.ContactStore' );
				}
				else {
					return Ext.create( 'MyApp.store.ContactStore' );
				}
			},
			eager: true
		},
		contactManager: {
			fn: function( instance ) {
				if ( instance.session.getIsAdmin() ) {
					return Ext.create( 'MyApp.manager.admin.ContactManager' );
				}
				else {
					return Ext.create( 'MyApp.manager.user.ContactManager' );
				}
			},
			singleton: false
		},
		...
	});
 
When the Injector is called to resolve dependencies for these identifiers, the factory function is called and the dependency is resolved with the return value.

As shown above, a lazily instantiated factory function can optionally accept a parameter, corresponding to the instance for which the Injector is currently injecting dependencies.

Factory function dependency providers can be configured as singletons or prototypes and can be eagerly or lazily instantiated.

*NOTE:* Only singleton factory functions can be eagerly instantiated.

**Values**

The Injector can also be configured to map identifiers to values:

	Deft.Injector.configure({
		brandedApplicationName: {
			value: "Contact Manager"
		},
		versionNumber: {
			value: 1.0
		},
		modules: {
			value: [ 'contacts', 'customers', 'orders' ]
		},
		...
	});

A value can be any native JavaScript type, including Strings, Arrays, Numbers, Objects or class instances… even Functions!

*NOTE:* Values can only be configured as singletons and cannot be eagerly instantiated.

## Deft.mixin.Injectable

A class is marked as participating in dependency injection by including the Injectable mixin:

	Ext.define( 'MyApp.manager.ContactManager', {
		extend: 'MyApp.manager.AbstractManager',
		mixins: [ 'Deft.mixin.Injectable' ],
		...
	});

Its dependencies are expressed using the `inject` annotation:

	Ext.define( 'MyApp.manager.ContactManager', {
		extend: 'MyApp.manager.AbstractManager',
		mixins: [ 'Deft.mixin.Injectable' ],
		
		inject: [ 'contactManager' ],
		...
	});

Any class that includes the Injectable mixin will have the dependencies described in its `inject` annotation resolved and injected by the Injector prior to the class constructor being called.

By default, each dependency will be injected into the config or property of the same name.

You can override this behavior and indicate the specific property to inject into, by using slightly more verbose syntax:

	Ext.define( 'MyApp.manager.ContactManager',
		extend: 'MyApp.manager.AbstractManager',
		mixins: [ 'Deft.mixin.Injectable' ],
		
		inject: {
			manager: 'contactManager'
		},
		...
	});

In this case, the `contactManager` dependency will be resolved into a new `manager` property.

A class does not need to explicitly define a config or property for the property to be injected.  However, if that property is defined as an existing config (even in a superclass), the Injector will correctly populate the config value.

	Ext.define( 'MyApp.manager.ContactManager',
		extend: 'MyApp.manager.AbstractManager',
		mixins: [ 'Deft.mixin.Injectable' ],
		
		inject: {
			manager: 'contactManager'
		},
		
		config: {
			manager: null
		},<commit_msg>Fixed typos in README examples.<commit_after># DeftJS

DeftJS is a micro-architecture that enables nimble development of enterprise class web applications with Ext JS and Sencha Touch.

# Goals

DeftJS enhances Ext JS and Sencha Touch's APIs with patterns and best practices discovered by top RIA developers at some of the best consulting firms in the industry.

DeftJS provides:

* **Simplicity**
	* Eliminates boilerplate code in favor of the simplest expression of developer intent.
* **Approachability**
	* Builds on familiar Ext JS API syntax conventions for 'pay-as-you-go' complexity.
* **Flexibility**
	* Coordinates dynamic assembly of object dependencies based on a configurable IoC container.
* **Reusability**
	* Enables business layer code reuse between Ext JS and Sencha Touch applications.
* **Testability**
	* Promotes loose coupling through class annotation driven dependency injection.

DeftJS provides the building blocks for scaling up to meet the needs of large enterprise class applications and development teams.

# Features

* **IoC Container**
	* Provides class annotation driven dependency injection.
	* Maps dependencies by user-defined identifiers.
	* Resolves dependencies by class instance, factory function or value.
	* Supports singleton and prototype resolution of class instance and factory function dependencies.
	* Offers eager and lazy instantiation of dependencies.
	* Injects dependencies into Ext JS class configs and properties before the class constructor is executed.

# API

## Deft.ioc.Injector

A lightweight IoC container for dependency injection.

### Configuration

**Classes**

In the simplest scenario, the Injector can be configured to map identifiers by class names:

	Deft.Injector.configure({
		contactStore: 'MyApp.store.ContactStore',
		contactManager: 'MyApp.manager.ContactManager',
		...
	});

When the Injector is called to resolve dependencies for these identifiers, a singleton instance of the specified class will be created and returned.

Where necessary, you can also specify constructor parameters:

	Deft.Injector.configure({
		contactStore: {
			className: 'MyApp.store.ContactStore',
			parameters: [{
				proxy: {
					type: 'ajax',
					url: '/contacts.json',
					reader: {
						type: 'json',
						root: 'contacts'
					}
				}
			}]
		},
		contactManager: 'MyApp.manager.ContactManager',
		...
	});

You can also specify whether a class is instantiated as a singleton (the default) or a prototype:

	Deft.Injector.configure({
		contactController: {
			className: 'MyApp.controller.ContactViewController',
			singleton: false
		},
		...
	});

Additionally, you can configure dependency providers to be eagerly or lazily (the default) instantiated:

	Deft.Injector.configure({
		preferences:  {
			preferences: 'MyApp.preferences.Preferences',
			eager: true
		},
		...
	});

When a dependency provider is configured for eager instantiation, it will be created and cached in the Injector immediately after all the identifiers in that `configure()` call have been processed.

*NOTE:* Only singletons can be eagerly instantiated.

**Factory Functions**

The Injector can also be configured to map identifiers to factory functions:

	Deft.Injector.configure({
		contactStore: {
			fn: function() {
				if ( useMocks ) {
					return Ext.create( 'MyApp.mock.store.ContactStore' );
				}
				else {
					return Ext.create( 'MyApp.store.ContactStore' );
				}
			},
			eager: true
		},
		contactManager: {
			fn: function( instance ) {
				if ( instance.session.getIsAdmin() ) {
					return Ext.create( 'MyApp.manager.admin.ContactManager' );
				}
				else {
					return Ext.create( 'MyApp.manager.user.ContactManager' );
				}
			},
			singleton: false
		},
		...
	});
 
When the Injector is called to resolve dependencies for these identifiers, the factory function is called and the dependency is resolved with the return value.

As shown above, a lazily instantiated factory function can optionally accept a parameter, corresponding to the instance for which the Injector is currently injecting dependencies.

Factory function dependency providers can be configured as singletons or prototypes and can be eagerly or lazily instantiated.

*NOTE:* Only singleton factory functions can be eagerly instantiated.

**Values**

The Injector can also be configured to map identifiers to values:

	Deft.Injector.configure({
		brandedApplicationName: {
			value: "Contact Manager"
		},
		versionNumber: {
			value: 1.0
		},
		modules: {
			value: [ 'contacts', 'customers', 'orders' ]
		},
		...
	});

A value can be any native JavaScript type, including Strings, Arrays, Numbers, Objects or class instances… even Functions!

*NOTE:* Values can only be configured as singletons and cannot be eagerly instantiated.

## Deft.mixin.Injectable

A class is marked as participating in dependency injection by including the Injectable mixin:

	Ext.define( 'MyApp.manager.ContactManager', {
		extend: 'MyApp.manager.AbstractManager',
		mixins: [ 'Deft.mixin.Injectable' ],
		...
	});

Its dependencies are expressed using the `inject` annotation:

	Ext.define( 'MyApp.manager.ContactManager', {
		extend: 'MyApp.manager.AbstractManager',
		mixins: [ 'Deft.mixin.Injectable' ],
		
		inject: [ 'contactManager' ],
		...
	});

Any class that includes the Injectable mixin will have the dependencies described in its `inject` annotation resolved and injected by the Injector prior to the class constructor being called.

By default, each dependency will be injected into the config or property of the same name.

You can override this behavior and indicate the specific property to inject into, by using slightly more verbose syntax:

	Ext.define( 'MyApp.manager.ContactManager', {
		extend: 'MyApp.manager.AbstractManager',
		mixins: [ 'Deft.mixin.Injectable' ],
		
		inject: {
			manager: 'contactManager'
		},
		...
	});

In this case, the `contactManager` dependency will be resolved into a new `manager` property.

A class does not need to explicitly define a config or property for the property to be injected.  However, if that property is defined as an existing config (even in a superclass), the Injector will correctly populate the config value.

	Ext.define( 'MyApp.manager.ContactManager', {
		extend: 'MyApp.manager.AbstractManager',
		mixins: [ 'Deft.mixin.Injectable' ],
		
		inject: {
			manager: 'contactManager'
		},
		
		config: {
			manager: null
		},
{'fraction_non_alphanumeric': 0.08322932917316693, 'fraction_numerical': 0.00031201248049921997, 'mean_word_length': 4.035742340926944, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7499306', 'n_tokens_mistral': 3879, 'n_tokens_neox': 3422, 'n_words': 1410}