commit
This commit is contained in:
parent
70e2f7a8aa
commit
008d2f30d7
675 changed files with 189892 additions and 0 deletions
3
node_modules/extendible/.npmignore
generated
vendored
Normal file
3
node_modules/extendible/.npmignore
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
node_modules
|
||||
coverage
|
||||
.tern-port
|
23
node_modules/extendible/.travis.yml
generated
vendored
Normal file
23
node_modules/extendible/.travis.yml
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- "0.12"
|
||||
- "0.10"
|
||||
- "0.8"
|
||||
- "iojs"
|
||||
before_install:
|
||||
- "npm install -g npm@2.1.18"
|
||||
script:
|
||||
- "npm run test-travis"
|
||||
after_script:
|
||||
- "npm install coveralls@2.11.x && cat coverage/lcov.info | coveralls"
|
||||
matrix:
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- node_js: "0.8"
|
||||
- node_js: "iojs"
|
||||
notifications:
|
||||
irc:
|
||||
channels:
|
||||
- "irc.freenode.org#bigpipe"
|
||||
on_success: change
|
||||
on_failure: change
|
86
node_modules/extendible/README.md
generated
vendored
Normal file
86
node_modules/extendible/README.md
generated
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
# extendible
|
||||
|
||||
[![From bigpipe.io][from]](http://bigpipe.io)[![Version npm][version]](http://browsenpm.org/package/extendible)[![Build Status][build]](https://travis-ci.org/bigpipe/extendible)[![Dependencies][david]](https://david-dm.org/bigpipe/extendible)[![Coverage Status][cover]](https://coveralls.io/r/bigpipe/extendible?branch=master)
|
||||
|
||||
[from]: https://img.shields.io/badge/from-bigpipe.io-9d8dff.svg?style=flat-square
|
||||
[version]: http://img.shields.io/npm/v/extendible.svg?style=flat-square
|
||||
[build]: http://img.shields.io/travis/bigpipe/extendible/master.svg?style=flat-square
|
||||
[david]: https://img.shields.io/david/bigpipe/extendible.svg?style=flat-square
|
||||
[cover]: http://img.shields.io/coveralls/bigpipe/extendible/master.svg?style=flat-square
|
||||
|
||||
Extend your JavaScript constructor in the same way as would extend Backbone.js
|
||||
Models using the `extend` method. Extending and inheritance has never been
|
||||
easier and more developer friendly. While the original version was straight port
|
||||
of the Backbone's source it has been re factored and rewritten many times to the
|
||||
project it is today. It features:
|
||||
|
||||
- Backbone compatible `extend` API.
|
||||
- Support for EcmaScript 5 getters and setters.
|
||||
- Understands the difference between constructors that are created in `use
|
||||
strict` mode.
|
||||
|
||||
## Installation
|
||||
|
||||
The module is intended for server-side and browser usage. We use feature
|
||||
detection to ensure compatibility with EcmaScript 3 based environments. The
|
||||
module is distributed through `npm` and can be installed using:
|
||||
|
||||
```
|
||||
npm install --save extendible
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
In all example code we assume that you've already required the `extendible`
|
||||
module and saved it as the `extend` variable as shown in the following example:
|
||||
|
||||
```js
|
||||
var extend = require('extendible');
|
||||
```
|
||||
|
||||
The extend method should be on the constructor as `.extend` method:
|
||||
|
||||
```js
|
||||
function Word() {
|
||||
this.foo = 'bar';
|
||||
}
|
||||
|
||||
//
|
||||
// It should be added on the constructor, not as property on the prototype!
|
||||
//
|
||||
Word.extend = extend;
|
||||
```
|
||||
|
||||
To create a new **Foo** class of your own you call the `Foo.extend` method with
|
||||
2 arguments:
|
||||
|
||||
1. `Object` properties and methods that should be added to your extended class
|
||||
prototype. These will override existing properties, but it would not override
|
||||
the properties on the parent/root class that you extend on.
|
||||
2. `Object` properties and methods that should added on the `constructor`
|
||||
directly. So instead of being introduced on the `.prototype` it's directly
|
||||
added to the returned Function.
|
||||
|
||||
As the properties of the prototype and constructor are inherited from the
|
||||
parent/root constructor you can further extended using the same **extend**
|
||||
method:
|
||||
|
||||
```js
|
||||
var Hello = Word.extend({
|
||||
name: 'hello',
|
||||
say: function update() {
|
||||
console.log('the word is: '+ this.name);
|
||||
}
|
||||
});
|
||||
|
||||
var World = Hello.extend({
|
||||
name: 'world'
|
||||
});
|
||||
|
||||
var world = new World();
|
||||
world.say(); // 'the word is: world'
|
||||
```
|
||||
|
||||
### License
|
||||
|
||||
MIT
|
32
node_modules/extendible/example/index.js
generated
vendored
Normal file
32
node_modules/extendible/example/index.js
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
var extend = require('../')
|
||||
, EventEmitter = require('events').EventEmitter;
|
||||
|
||||
function Awesomeness() {
|
||||
var self = this;
|
||||
|
||||
setTimeout(function () {
|
||||
self.render(self.data);
|
||||
}, 100);
|
||||
|
||||
EventEmitter.call(this);
|
||||
}
|
||||
|
||||
Awesomeness.prototype = new EventEmitter;
|
||||
Awesomeness.prototype.constructor = Awesomeness;
|
||||
|
||||
Awesomeness.prototype.data = 'bar';
|
||||
Awesomeness.prototype.render = function render() {
|
||||
// does nothing
|
||||
};
|
||||
|
||||
Awesomeness.extend = extend;
|
||||
|
||||
var SuperAwesome = Awesomeness.extend({
|
||||
data: 'trololol'
|
||||
|
||||
, render: function render(data) {
|
||||
console.log(data);
|
||||
}
|
||||
});
|
||||
|
||||
new SuperAwesome();
|
140
node_modules/extendible/index.js
generated
vendored
Normal file
140
node_modules/extendible/index.js
generated
vendored
Normal file
|
@ -0,0 +1,140 @@
|
|||
// 'use strict'; //<-- Root of all evil, causes thrown errors on readyOnly props.
|
||||
|
||||
var has = Object.prototype.hasOwnProperty
|
||||
, slice = Array.prototype.slice;
|
||||
|
||||
/**
|
||||
* Copy all readable properties from an Object or function and past them on the
|
||||
* object.
|
||||
*
|
||||
* @param {Object} obj The object we should paste everything on.
|
||||
* @returns {Object} obj
|
||||
* @api private
|
||||
*/
|
||||
function copypaste(obj) {
|
||||
var args = slice.call(arguments, 1)
|
||||
, i = 0
|
||||
, prop;
|
||||
|
||||
for (; i < args.length; i++) {
|
||||
if (!args[i]) continue;
|
||||
|
||||
for (prop in args[i]) {
|
||||
if (!has.call(args[i], prop)) continue;
|
||||
|
||||
obj[prop] = args[i][prop];
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* A proper mixin function that respects getters and setters.
|
||||
*
|
||||
* @param {Object} obj The object that should receive all properties.
|
||||
* @returns {Object} obj
|
||||
* @api private
|
||||
*/
|
||||
function mixin(obj) {
|
||||
if (
|
||||
'function' !== typeof Object.getOwnPropertyNames
|
||||
|| 'function' !== typeof Object.defineProperty
|
||||
|| 'function' !== typeof Object.getOwnPropertyDescriptor
|
||||
) {
|
||||
return copypaste.apply(null, arguments);
|
||||
}
|
||||
|
||||
//
|
||||
// We can safely assume that if the methods we specify above are supported
|
||||
// that it's also save to use Array.forEach for iteration purposes.
|
||||
//
|
||||
slice.call(arguments, 1).forEach(function forEach(o) {
|
||||
Object.getOwnPropertyNames(o).forEach(function eachAttr(attr) {
|
||||
Object.defineProperty(obj, attr, Object.getOwnPropertyDescriptor(o, attr));
|
||||
});
|
||||
});
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect if a given parent is constructed in strict mode so we can force the
|
||||
* child in to the same mode. It detects the strict mode by accessing properties
|
||||
* on the function that are forbidden in strict mode:
|
||||
*
|
||||
* - `caller`
|
||||
* - `callee`
|
||||
* - `arguments`
|
||||
*
|
||||
* Forcing the a thrown TypeError.
|
||||
*
|
||||
* @param {Function} parent Parent constructor
|
||||
* @returns {Function} The child constructor
|
||||
* @api private
|
||||
*/
|
||||
function mode(parent) {
|
||||
try {
|
||||
var e = parent.caller || parent.arguments || parent.callee;
|
||||
|
||||
return function child() {
|
||||
return parent.apply(this, arguments);
|
||||
};
|
||||
} catch(e) {}
|
||||
|
||||
return function child() {
|
||||
'use strict';
|
||||
|
||||
return parent.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
// Helper function to correctly set up the prototype chain, for subclasses.
|
||||
// Similar to `goog.inherits`, but uses a hash of prototype properties and
|
||||
// class properties to be extended.
|
||||
//
|
||||
module.exports = function extend(protoProps, staticProps) {
|
||||
var parent = this
|
||||
, child;
|
||||
|
||||
//
|
||||
// The constructor function for the new subclass is either defined by you
|
||||
// (the "constructor" property in your `extend` definition), or defaulted
|
||||
// by us to simply call the parent's constructor.
|
||||
//
|
||||
if (protoProps && has.call(protoProps, 'constructor')) {
|
||||
child = protoProps.constructor;
|
||||
} else {
|
||||
child = mode(parent);
|
||||
}
|
||||
|
||||
//
|
||||
// Set the prototype chain to inherit from `parent`, without calling
|
||||
// `parent`'s constructor function.
|
||||
//
|
||||
function Surrogate() {
|
||||
this.constructor = child;
|
||||
}
|
||||
|
||||
Surrogate.prototype = parent.prototype;
|
||||
child.prototype = new Surrogate;
|
||||
|
||||
//
|
||||
// Add prototype properties (instance properties) to the subclass,
|
||||
// if supplied.
|
||||
//
|
||||
if (protoProps) mixin(child.prototype, protoProps);
|
||||
|
||||
//
|
||||
// Add static properties to the constructor function, if supplied.
|
||||
//
|
||||
copypaste(child, parent, staticProps);
|
||||
|
||||
//
|
||||
// Set a convenience property in case the parent's prototype is needed later.
|
||||
//
|
||||
child.__super__ = parent.prototype;
|
||||
|
||||
return child;
|
||||
};
|
44
node_modules/extendible/package.json
generated
vendored
Normal file
44
node_modules/extendible/package.json
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"name": "extendible",
|
||||
"version": "0.1.1",
|
||||
"description": "Extend constructors using backbone's .extend signature",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"100%": "istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100",
|
||||
"test": "mocha test.js",
|
||||
"watch": "mocha --watch test.js",
|
||||
"coverage": "istanbul cover ./node_modules/.bin/_mocha -- test.js",
|
||||
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/bigpipe/extendible"
|
||||
},
|
||||
"keywords": [
|
||||
"backbone",
|
||||
"extend",
|
||||
"extendable",
|
||||
"extendible",
|
||||
"extending",
|
||||
"extends",
|
||||
"inherit",
|
||||
"inherits",
|
||||
"lodash",
|
||||
"constructor",
|
||||
"inheritance",
|
||||
"mixin",
|
||||
"mixins"
|
||||
],
|
||||
"author": "Arnout Kazemier",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/bigpipe/extendible/issues"
|
||||
},
|
||||
"homepage": "https://github.com/bigpipe/extendible",
|
||||
"devDependencies": {
|
||||
"assume": "1.2.x",
|
||||
"istanbul": "0.3.x",
|
||||
"mocha": "2.2.x",
|
||||
"pre-commit": "1.0.x"
|
||||
}
|
||||
}
|
117
node_modules/extendible/test.js
generated
vendored
Normal file
117
node_modules/extendible/test.js
generated
vendored
Normal file
|
@ -0,0 +1,117 @@
|
|||
describe('extendible', function () {
|
||||
// 'use strict'; // Disabled for strict-mode vs global mode tests;
|
||||
var assume = require('assume')
|
||||
, extend = require('./')
|
||||
, Foo;
|
||||
|
||||
beforeEach(function each() {
|
||||
Foo = function Foo() {};
|
||||
Foo.extend = extend;
|
||||
});
|
||||
|
||||
it('is exported as function', function () {
|
||||
assume(extend).is.a('function');
|
||||
});
|
||||
|
||||
it('returns the newly extended function', function () {
|
||||
var Bar = Foo.extend();
|
||||
assume(Bar).does.not.equal(Foo);
|
||||
});
|
||||
|
||||
it('can override properties and methods', function () {
|
||||
/* istanbul ignore next */
|
||||
Foo.prototype.bar = function () { return true; };
|
||||
Foo.prototype.prop = 10;
|
||||
|
||||
var Bar = Foo.extend({
|
||||
bar: function () {
|
||||
return false;
|
||||
},
|
||||
prop: 'foo'
|
||||
});
|
||||
|
||||
var bar = new Bar();
|
||||
|
||||
assume(bar.bar()).is.false();
|
||||
assume(bar.prop).equals('foo');
|
||||
});
|
||||
|
||||
it('correctly inherits and overrides getters', function () {
|
||||
var Bar = Foo.extend({
|
||||
get hello() {
|
||||
return 'hi';
|
||||
}
|
||||
});
|
||||
|
||||
var Baz = Bar.extend({
|
||||
yes: false
|
||||
});
|
||||
|
||||
var bar = new Baz();
|
||||
|
||||
assume(bar.yes).equals(false);
|
||||
assume(bar.hello).equals('hi');
|
||||
|
||||
var Override = Bar.extend({
|
||||
hello: 'world'
|
||||
});
|
||||
|
||||
var override = new Override();
|
||||
assume(override.hello).equals('world');
|
||||
});
|
||||
|
||||
it('returns the value from the parent constructor', function () {
|
||||
var Baz = function () {
|
||||
return {
|
||||
my: 'name is '+ this.name
|
||||
};
|
||||
};
|
||||
|
||||
Baz.prototype.name = 'baz';
|
||||
Baz.extend = extend;
|
||||
|
||||
var Bob = Baz.extend({
|
||||
name: 'bob'
|
||||
});
|
||||
|
||||
var bob = new Bob()
|
||||
, baz = new Baz();
|
||||
|
||||
assume(baz.my).equals('name is baz');
|
||||
assume(bob.my).equals('name is bob');
|
||||
});
|
||||
|
||||
it('runs in strict mode if the parent runs in strict mode', function (next) {
|
||||
next = assume.plan(2, next);
|
||||
|
||||
var Baz = function () {
|
||||
'use strict';
|
||||
|
||||
assume(this).equals(undefined);
|
||||
};
|
||||
|
||||
Baz.extend = extend;
|
||||
|
||||
var Bar = Baz.extend()
|
||||
, bar = Bar()
|
||||
, baz = Baz();
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
it('runs in does not run in strict mode if the parent isnt', function (next) {
|
||||
next = assume.plan(2, next);
|
||||
|
||||
var Baz = function () {
|
||||
assume(this).equals(global);
|
||||
};
|
||||
|
||||
Baz.extend = extend;
|
||||
|
||||
var Bar = Baz.extend()
|
||||
, bar = Bar()
|
||||
, baz = Baz();
|
||||
|
||||
next();
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue