Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Properly bundle npm dependency

  • Loading branch information...
commit 8fb7917ee8c9cff174b293b5f74dedc51f764f62 1 parent 8867aa4
Felix Geisendörfer authored
2  .gitignore
... ... @@ -0,0 +1,2 @@
  1 +*.un~
  2 +/node_modules
4 node_modules/oop/Makefile
... ... @@ -1,4 +0,0 @@
1   -SHELL := /bin/bash
2   -
3   -test-integration:
4   - @find test/integration/test-*.js | xargs -n 1 -t node
11 node_modules/oop/Readme.md
Source Rendered
... ... @@ -1,11 +0,0 @@
1   -# oop
2   -
3   -## Purpose
4   -
5   -This library tries to bring basic oop features to JavaScript while being as
6   -light-weight and simple as possible.
7   -
8   -
9   -## Todo
10   -
11   -* Documentation
1  node_modules/oop/lib/index.js
... ... @@ -1 +0,0 @@
1   -module.exports = require('./oop');
131 node_modules/oop/lib/oop.js
... ... @@ -1,131 +0,0 @@
1   -var oop = exports;
2   -
3   -oop.forceMixin = function(child /*, Parent1, ... */) {
4   - for (i = 1; i < arguments.length; i++) {
5   - oop._forceMixin(child, arguments[i]);
6   - }
7   -};
8   -oop.mixin = oop.forceMixin;
9   -
10   -oop._forceMixin = function(child, Parent) {
11   - oop._forceCopyPrototype(child, Parent);
12   - Parent.call(child);
13   -};
14   -
15   -oop._forceCopyPrototype = function(child, Parent) {
16   - for (var property in Parent.prototype) {
17   - oop._copyPrototypeProperty(child, Parent, property);
18   - };
19   -};
20   -
21   -oop._copyPrototypeProperty = function(child, Parent, property) {
22   - Object.defineProperty(child, property, {
23   - value: Parent.prototype[property],
24   - writable: true,
25   - enumerable: false,
26   - configurable: true
27   - });
28   -};
29   -
30   -oop.strictMixin = function(child /*, Parent1, ... */) {
31   - for (i = 1; i < arguments.length; i++) {
32   - oop._strictMixin(child, arguments[i]);
33   - }
34   -};
35   -
36   -oop._strictMixin = function(child, Parent) {
37   - oop._strictCopyPrototype(child, Parent);
38   - oop._strictCallConstructor(child, Parent);
39   -};
40   -
41   -oop._strictCopyPrototype = function(child, Parent) {
42   - for (var property in Parent.prototype) {
43   - if (child[property] === undefined) {
44   - oop._copyPrototypeProperty(child, Parent, property);
45   - continue;
46   - }
47   -
48   - oop._error(
49   - 'oop.strictMixin(): Class "' + Parent.name + '" tried to overwrite ' +
50   - 'prototype property "' + property + '".'
51   - , oop.strictMixin);
52   - };
53   -};
54   -
55   -oop._strictCallConstructor = function(child, Parent) {
56   - var original = {};
57   - for (var property in child) {
58   - original[property] = child[property];
59   - }
60   -
61   - Parent.call(child);
62   -
63   - for (var property in original) {
64   - if (child[property] === original[property]) {
65   - continue;
66   - }
67   -
68   - oop._error(
69   - 'oop.mixin(): Class "' + Parent.name +
70   - '" tried to overwrite property "' + property + '".'
71   - , oop.strictMixin);
72   - }
73   -};
74   -
75   -oop.softMixin = function(child /*, Parent1, ... */) {
76   - for (i = 1; i < arguments.length; i++) {
77   - oop._softMixin(child, arguments[i]);
78   - }
79   -};
80   -
81   -oop._softMixin = function(child, Parent) {
82   - oop._softCopyPrototype(child, Parent);
83   - oop._softCallConstructor(child, Parent);
84   -};
85   -
86   -oop._softCopyPrototype = function(child, Parent) {
87   - for (var property in Parent.prototype) {
88   - if (child[property] !== undefined) {
89   - continue;
90   - }
91   -
92   - oop._copyPrototypeProperty(child, Parent, property);
93   - };
94   -};
95   -
96   -oop._softCallConstructor = function(child, Parent) {
97   - var original = {};
98   - for (var property in child) {
99   - original[property] = child[property];
100   - }
101   -
102   - Parent.call(child);
103   -
104   - for (var property in original) {
105   - child[property] = original[property];
106   - }
107   -};
108   -
109   -oop._error = function(message, traceOrigin) {
110   - var error = new Error(message);
111   - Error.captureStackTrace(error, traceOrigin);
112   - throw error;
113   -};
114   -
115   -
116   -oop.extend = function(Child, Parent) {
117   - Child.prototype = Object.create(Parent.prototype, {
118   - constructor: {
119   - value: Child,
120   - enumerable: false
121   - }
122   - });
123   -
124   - for (var property in Parent) {
125   - if (Child[property] !== undefined) {
126   - continue;
127   - }
128   -
129   - Child[property] = Parent[property];
130   - }
131   -};
10 node_modules/oop/package.json
... ... @@ -1,10 +0,0 @@
1   -{
2   - "name": "oop",
3   - "author": "Felix Geisendörfer <felix@debuggable.com> (http://debuggable.com/)",
4   - "description": "Simple & light-weight oop.",
5   - "version": "0.0.3",
6   - "main": "./lib/index.js",
7   - "engines": {
8   - "node": ">=0.4.0"
9   - }
10   -}
2  node_modules/oop/test/common.js
... ... @@ -1,2 +0,0 @@
1   -var common = exports;
2   -common.oop = require('../lib/oop');
59 node_modules/oop/test/integration/test-force-mixin.js
... ... @@ -1,59 +0,0 @@
1   -var common = require('../common');
2   -var oop = common.oop;
3   -var assert = require('assert');
4   -
5   -function Friendly() {
6   - // Properties from the mixed in class should be copied
7   - this.friendly = true;
8   - this.overWriteMe = 'Friendly';
9   -
10   - // Methods of the mixed in class should be callable from the constructor
11   - this.greet();
12   -}
13   -
14   -Friendly.prototype.greet = function() {
15   -};
16   -
17   -function Tall() {
18   - this.tall = true;
19   - this.overWriteMe = 'Tall';
20   -
21   - this.slamdunk();
22   -}
23   -
24   -Tall.prototype.slamdunk = function() {
25   -}
26   -
27   -function Person() {
28   - // The properties of the mixin target should be kept
29   - this.person = true;
30   - // Unless they are overwritten by one of the mixins
31   - this.overWriteMe = 'Person';
32   -
33   - // Mixins are runtime created
34   - oop.forceMixin(this, Friendly, Tall);
35   -}
36   -
37   -Person.prototype.whimper = function() {
38   -}
39   -
40   -var person = new Person();
41   -// Make sure all properties got copied
42   -assert.ok(person.person);
43   -assert.ok(person.friendly);
44   -assert.ok(person.tall);
45   -
46   -// Make sure overWriteMe got overwritten by the last mixin
47   -assert.strictEqual(person.overWriteMe, 'Tall');
48   -
49   -// Make sure all methods got copied
50   -person.whimper();
51   -person.greet();
52   -person.slamdunk();
53   -
54   -// Make sure only the properties are enumerable
55   -var properties = Object.keys(person);
56   -assert.deepEqual(properties, ['person', 'overWriteMe', 'friendly', 'tall']);
57   -
58   -// Make sure mixin is an alias of forceMixin
59   -assert.strictEqual(oop.mixin, oop.forceMixin);
35 node_modules/oop/test/integration/test-inherits.js
... ... @@ -1,35 +0,0 @@
1   -var common = require('../common');
2   -var oop = common.oop;
3   -var assert = require('assert');
4   -
5   -function A() {
6   - this.a = true;
7   -}
8   -A.methodA = function() {};
9   -
10   -function B() {
11   - A.call(this);
12   -
13   - this.b = true;
14   -}
15   -oop.extend(B, A);
16   -
17   -B.methodB = function() {};
18   -
19   -function C() {
20   - B.call(this);
21   -}
22   -oop.extend(C, B);
23   -
24   -var c = new C();
25   -assert.ok(c instanceof C);
26   -assert.ok(c instanceof B);
27   -assert.ok(c instanceof A);
28   -
29   -assert.ok(c.a);
30   -assert.ok(c.b);
31   -
32   -C.methodA();
33   -C.methodB();
34   -
35   -assert.strictEqual(c.constructor, C);
36 node_modules/oop/test/integration/test-soft-mixin.js
... ... @@ -1,36 +0,0 @@
1   -var common = require('../common');
2   -var oop = common.oop;
3   -var assert = require('assert');
4   -
5   -function A() {
6   - this.propertyA = true;
7   - this.sharedProperty = 'A';
8   -}
9   -A.prototype.methodA = function() {}
10   -A.prototype.sharedMethod = function() {}
11   -
12   -function B() {
13   - this.propertyB = true;
14   - this.sharedProperty = 'B';
15   -
16   - oop.softMixin(this, A);
17   -}
18   -B.prototype.methodB = function() {}
19   -B.prototype.sharedMethod = function() {}
20   -
21   -var b = new B();
22   -// Make sure individual properties got copied
23   -assert.ok(b.propertyA);
24   -assert.ok(b.propertyB);
25   -
26   -// Make sure that mixin A didn't overwrite shared property B
27   -assert.strictEqual(b.sharedProperty, 'B');
28   -
29   -// Make sure all methods got copied and are callable
30   -b.methodA();
31   -b.methodB();
32   -b.sharedMethod();
33   -
34   -// Check that our sharedMethod comes from B and wasn't overwritten by mixin A
35   -assert.strictEqual(b.sharedMethod, B.prototype.sharedMethod);
36   -assert.notStrictEqual(b.sharedMethod, A.prototype.sharedMethod);
19 node_modules/oop/test/integration/test-strict-mixin-property-conflict.js
... ... @@ -1,19 +0,0 @@
1   -var common = require('../common');
2   -var oop = common.oop;
3   -var assert = require('assert');
4   -
5   -function A() {
6   - this.myProperty = 'foo';
7   -}
8   -
9   -function B() {
10   - this.myProperty = 'bar';
11   -}
12   -
13   -function C() {
14   - oop.strictMixin(this, A, B);
15   -}
16   -
17   -assert.throws(function() {
18   - var c = new C();
19   -}, /class "B".+property "myProperty"/i);
17 node_modules/oop/test/integration/test-strict-mixin-prototype-conflict.js
... ... @@ -1,17 +0,0 @@
1   -var common = require('../common');
2   -var oop = common.oop;
3   -var assert = require('assert');
4   -
5   -function A() {}
6   -A.prototype.myMethod = function() {};
7   -
8   -function B() {}
9   -B.prototype.myMethod = function() {};
10   -
11   -function C() {
12   - oop.strictMixin(this, A, B);
13   -}
14   -
15   -assert.throws(function() {
16   - var c = new C();
17   -}, /class "B".+prototype property "myMethod"/i);
5 package.json
@@ -9,10 +9,13 @@
9 9 },
10 10 "author": "Felix Geisendörfer <felix@debuggable.com> (http://debuggable.com/)",
11 11 "main": "./lib/m3u.js",
  12 + "dependencies": {
  13 + "oop": "0.0.3"
  14 + },
12 15 "directories": {
13 16 "lib": "lib"
14 17 },
15 18 "engines": {
16 19 "node": "*"
17 20 }
18   -}
  21 +}

0 comments on commit 8fb7917

Please sign in to comment.
Something went wrong with that request. Please try again.