Skip to content

Commit

Permalink
v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Ellis authored and Jack Ellis committed Mar 25, 2017
1 parent 8fc9f9b commit 664ce36
Show file tree
Hide file tree
Showing 34 changed files with 136 additions and 1,317 deletions.
2 changes: 1 addition & 1 deletion .publishrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"gitTag": true
},
"confirm": false,
"publishTag": "alpha",
"publishTag": "latest",
"prePublishScript": "npm run build"
}
149 changes: 133 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,146 @@
JPEX - Javascipt Protoype Extension
===================================
[![Build Status](https://travis-ci.org/jackmellis/jpex.svg?branch=master)](https://travis-ci.org/jackmellis/jpex)

![Jpex](https://jpex-js.github.io/dist/jpex.svg)
===========
Easy Dependency Injection
--------------------------

[![Build Status](https://travis-ci.org/jpex-js/jpex.svg?branch=master)](https://travis-ci.org/jackmellis/jpex)
[![npm version](https://badge.fury.io/js/jpex.svg)](https://badge.fury.io/js/jpex)
[![Code Climate](https://codeclimate.com/github/jackmellis/jpex/badges/gpa.svg)](https://codeclimate.com/github/jackmellis/jpex)
[![Test Coverage](https://codeclimate.com/github/jackmellis/jpex/badges/coverage.svg)](https://codeclimate.com/github/jackmellis/jpex/coverage)

Jpex is a Class wrapper and Inversion of Control framework.

Jpex makes it easy to create an Object-Oriented-style application in Node. It wraps up a lot of the prototypical quirks of Javascript so you can focus on creating purposeful classes. This is an intentional move away from static functions and modules in favour of providing all complex objects in the form of class instances.
*This the 2.0 of Jpex. For version 1, please refer to the [v1](https://github.com/jpex-js/jpex/blob/1.x/docs/index.md) docs*

The second purpose of Jpex is to make dependency injection extremely easy. You shouldn't ever have to `require` a module within your application (other than Jpex itself), but you also shouldn't have to worry about manually injecting dependencies into every class.
Nobody wants to call a function with 20 parameters in a specific order.
It's not readable, maintainable, or fun. Proper dependency injection should be automagical and the caller shouldn't care what the callee depends on.
## Getting Started

Usage
-----
Easy: require, extend, and instantiate!
### Install
Jpex is available on [npm](https://www.npmjs.com/package/jpex):
`npm install jpex --save`

You can then include Jpex in your commonJs project:
```javascript
var jpex = require('jpex');
var Jpex = require('jpex');
Jpex.extend(...);
```
Which works out-of-the-box with *node*, *webpack* and *browserify*

Jpex also comes with a pre-built js file which can be included as a script tag on your page:
```
<script src="node_modules/jpex/dist/jpex.js"></script>
<script>
Jpex.extend(...);
</script>
```

var MyClass = jpex.extend(function($log){
this.thing = 'hello';
$log('My Class instantiated');
You can also download the source code from [github](https://github.com/jpex-js/jpex)

------

### Registering Services
Services and factories are small modules or functions that provide a reusable or common piece of functionality. In Jpex, you can register **factories**:
```javascript
Jpex.register.factory('myFactory', function(){
return {};
});
```
**services**:
```javascript
Jpex.register.service('myService', function(){
this.method = function(){
...
};
});
```
and **constants**:
```javascript
Jpex.register.constant('myConstant', 'foo');
```

------

### Using Factories
Once registered, you can request any factory when creating a new Jpex class:
```javascript
var Class = Jpex.extend(function(myFactory, myService, myConstant){
myService.method();
myConstant === 'foo';
});

new Class(); // creates an instance of Class using the above constructor function.
```

var instance = new MyClass();
You can also request a factory from Jpex directly:
```javascript
var myService = Jpex.$resolve('myService');
var myConstant = Jpex.$resolve('myConstant');

myService.method();
myConstant === 'foo';
```
There is much more that can be done with Jpex. Checkout the full documentation at https://github.com/jackmellis/jpex/blob/master/docs/index.md

And finally, you can request a dependency from within another factory:
```javascript
Jpex.register.constant('myConstant', 'foo');

Jpex.register.factory('myFactory', function(myConstant){
return {
injectedValue : myConstant
};
});

Jpex.register.service('myService', function(myFactory){
this.method = function(){
return myFactory.injectedValue;
};
});

Jpex.$resolve('myService').method(); // returns 'foo'!
```

-------

### Extend &amp; Instantiate
You can `extend` Jpex to create a whole new *class* with its own constructor and factories. You can also extend an extended class and so on. Each extended class inherits its parent's properties and factories.
```javascript
var Class = Jpex.extend(function(inheritedService){
// ...
});

var SubClass = Class.extend({
constructor : function(inheritedService){
...
},
invokeParent : true, // will fire off the parent constructor
methods : {
methodA : function(){
// ...
}
}
});
```
you can invoke a Jpex class with the `new` keyword. This will create a new instance of the class:
```javascript
var instance = new SubClass();

instance.methodA();
```

------

### Plugins
There are several [plugins](/plugins) available that add extra functionality to Jpex. The most fundamental are [jpex-node](https://www.npmjs.com/package/jpex-node) and [jpex-web](https://www.npmjs.com/package/jpex-web) that add some useful default factories to your node or web application:
```javascript
Jpex.use(require('jpex-node'));
Jpex.$resolve('$fs');
Jpex.$resolve('$promise');

// or
Jpex.use(require('jpex-web'));
Jpex.$resolve('$window');

// etc.
```

For more information, see the full documentation at [https://jpex-js.github.io](https://jpex-js.github.io)
File renamed without changes.
40 changes: 0 additions & 40 deletions docs/api/defaults/copy.md

This file was deleted.

46 changes: 0 additions & 46 deletions docs/api/defaults/error.md

This file was deleted.

13 changes: 0 additions & 13 deletions docs/api/defaults/fs.md

This file was deleted.

14 changes: 0 additions & 14 deletions docs/api/defaults/log.md

This file was deleted.

44 changes: 0 additions & 44 deletions docs/api/defaults/promise.md

This file was deleted.

13 changes: 0 additions & 13 deletions docs/api/defaults/resolve.md

This file was deleted.

45 changes: 0 additions & 45 deletions docs/api/defaults/timers.md

This file was deleted.

Loading

0 comments on commit 664ce36

Please # to comment.