-
Notifications
You must be signed in to change notification settings - Fork 0
/
concur.js
157 lines (134 loc) · 5.53 KB
/
concur.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* Concur 0.3.0 - https://github.com/insin/concur
* MIT Licensed
*/
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Concur=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var hasOwn = Object.prototype.hasOwnProperty
var toString = Object.prototype.toString
function type(obj) {
return toString.call(obj).slice(8, -1).toLowerCase()
}
function inherits(childConstructor, parentConstructor) {
var F = function() {}
F.prototype = parentConstructor.prototype
childConstructor.prototype = new F()
childConstructor.prototype.constructor = childConstructor
return childConstructor
}
function extend(dest, src) {
for (var prop in src) {
if (hasOwn.call(src, prop)) {
dest[prop] = src[prop]
}
}
return dest
}
/**
* Mixes in properties from one object to another. If the source object is a
* Function, its prototype is mixed in instead.
*/
function mixin(dest, src) {
if (type(src) == 'function') {
extend(dest, src.prototype)
}
else {
extend(dest, src)
}
}
/**
* Applies mixins specified as a __mixins__ property on the given properties
* object, returning an object containing the mixed in properties.
*/
function applyMixins(properties) {
var mixins = properties.__mixins__
if (type(mixins) != 'array') {
mixins = [mixins]
}
var mixedProperties = {}
for (var i = 0, l = mixins.length; i < l; i++) {
mixin(mixedProperties, mixins[i])
}
delete properties.__mixins__
return extend(mixedProperties, properties)
}
/**
* Inherits another constructor's prototype and sets its prototype and
* constructor properties in one fell swoop.
*
* If a child constructor is not provided via prototypeProps.constructor,
* a new constructor will be created.
*/
function inheritFrom(parentConstructor, childConstructor, prototypeProps, constructorProps) {
// Create a child constructor if one wasn't given
if (childConstructor == null) {
childConstructor = function() {
parentConstructor.apply(this, arguments)
}
}
// Make sure the new prototype has the correct constructor set up
prototypeProps.constructor = childConstructor
// Base constructors should only have the properties they're defined with
if (parentConstructor !== Concur) {
// Inherit the parent's prototype
inherits(childConstructor, parentConstructor)
childConstructor.__super__ = parentConstructor.prototype
}
// Add prototype properties - this is why we took a copy of the child
// constructor reference in extend() - if a .constructor had been passed as a
// __mixins__ and overitten prototypeProps.constructor, these properties would
// be getting set on the mixed-in constructor's prototype.
extend(childConstructor.prototype, prototypeProps)
// Add constructor properties
extend(childConstructor, constructorProps)
return childConstructor
}
/**
* Namespace and dummy constructor for initial extension.
*/
var Concur = module.exports = function() {}
/**
* Details of a constructor's inheritance chain - Concur just facilitates sugar
* so we don't include it in the initial chain. Arguably, Object.prototype could
* go here, but it's just not that interesting.
*/
Concur.__mro__ = []
/**
* Creates or uses a child constructor to inherit from the the call
* context, which is expected to be a constructor.
*/
Concur.extend = function(prototypeProps, constructorProps) {
// Ensure we have prop objects to work with
prototypeProps = prototypeProps || {}
constructorProps = constructorProps || {}
// If the constructor being inherited from has a __meta__ function somewhere
// in its prototype chain, call it to customise prototype and constructor
// properties before they're used to set up the new constructor's prototype.
if (typeof this.prototype.__meta__ != 'undefined') {
this.prototype.__meta__(prototypeProps, constructorProps)
}
// Any child constructor passed in should take precedence - grab a reference
// to it befoer we apply any mixins.
var childConstructor = (hasOwn.call(prototypeProps, 'constructor')
? prototypeProps.constructor
: null)
// If any mixins are specified, mix them into the property objects
if (hasOwn.call(prototypeProps, '__mixins__')) {
prototypeProps = applyMixins(prototypeProps)
}
if (hasOwn.call(constructorProps, '__mixins__')) {
constructorProps = applyMixins(constructorProps)
}
// Set up the new child constructor and its prototype
childConstructor = inheritFrom(this,
childConstructor,
prototypeProps,
constructorProps)
// Pass on the extend function for extension in turn
childConstructor.extend = this.extend
// Expose the inheritance chain for programmatic access
childConstructor.__mro__ = [childConstructor].concat(this.__mro__)
return childConstructor
}
},{}]},{},[1])(1)
});