-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
4,394 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*can-reflect@1.17.6#can-reflect*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'./reflections/call/call', | ||
'./reflections/get-set/get-set', | ||
'./reflections/observe/observe', | ||
'./reflections/shape/shape', | ||
'./reflections/shape/schema/schema', | ||
'./reflections/type/type', | ||
'./reflections/get-name/get-name', | ||
'can-namespace', | ||
'./types/map', | ||
'./types/set' | ||
], function (require, exports, module) { | ||
'use strict'; | ||
var functionReflections = require('./reflections/call/call'); | ||
var getSet = require('./reflections/get-set/get-set'); | ||
var observe = require('./reflections/observe/observe'); | ||
var shape = require('./reflections/shape/shape'); | ||
var schema = require('./reflections/shape/schema/schema'); | ||
var type = require('./reflections/type/type'); | ||
var getName = require('./reflections/get-name/get-name'); | ||
var namespace = require('can-namespace'); | ||
var reflect = {}; | ||
[ | ||
functionReflections, | ||
getSet, | ||
observe, | ||
shape, | ||
type, | ||
getName, | ||
schema | ||
].forEach(function (reflections) { | ||
for (var prop in reflections) { | ||
reflect[prop] = reflections[prop]; | ||
} | ||
}); | ||
require('./types/map'); | ||
require('./types/set'); | ||
module.exports = namespace.Reflect = reflect; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*can-reflect@1.17.6#reflections/call/call*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-symbol', | ||
'../type/type' | ||
], function (require, exports, module) { | ||
'use strict'; | ||
var canSymbol = require('can-symbol'); | ||
var typeReflections = require('../type/type'); | ||
module.exports = { | ||
call: function (func, context) { | ||
var args = [].slice.call(arguments, 2); | ||
var apply = func[canSymbol.for('can.apply')]; | ||
if (apply) { | ||
return apply.call(func, context, args); | ||
} else { | ||
return func.apply(context, args); | ||
} | ||
}, | ||
apply: function (func, context, args) { | ||
var apply = func[canSymbol.for('can.apply')]; | ||
if (apply) { | ||
return apply.call(func, context, args); | ||
} else { | ||
return func.apply(context, args); | ||
} | ||
}, | ||
'new': function (func) { | ||
var args = [].slice.call(arguments, 1); | ||
var makeNew = func[canSymbol.for('can.new')]; | ||
if (makeNew) { | ||
return makeNew.apply(func, args); | ||
} else { | ||
var context = Object.create(func.prototype); | ||
var ret = func.apply(context, args); | ||
if (typeReflections.isPrimitive(ret)) { | ||
return context; | ||
} else { | ||
return ret; | ||
} | ||
} | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/*can-reflect@1.17.6#reflections/get-name/get-name*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-symbol', | ||
'../type/type' | ||
], function (require, exports, module) { | ||
'use strict'; | ||
var canSymbol = require('can-symbol'); | ||
var typeReflections = require('../type/type'); | ||
var getNameSymbol = canSymbol.for('can.getName'); | ||
function setName(obj, nameGetter) { | ||
if (typeof nameGetter !== 'function') { | ||
var value = nameGetter; | ||
nameGetter = function () { | ||
return value; | ||
}; | ||
} | ||
Object.defineProperty(obj, getNameSymbol, { value: nameGetter }); | ||
} | ||
var anonymousID = 0; | ||
function getName(obj) { | ||
var type = typeof obj; | ||
if (obj === null || type !== 'object' && type !== 'function') { | ||
return '' + obj; | ||
} | ||
var nameGetter = obj[getNameSymbol]; | ||
if (nameGetter) { | ||
return nameGetter.call(obj); | ||
} | ||
if (type === 'function') { | ||
if (!('name' in obj)) { | ||
obj.name = 'functionIE' + anonymousID++; | ||
} | ||
return obj.name; | ||
} | ||
if (obj.constructor && obj !== obj.constructor) { | ||
var parent = getName(obj.constructor); | ||
if (parent) { | ||
if (typeReflections.isValueLike(obj)) { | ||
return parent + '<>'; | ||
} | ||
if (typeReflections.isMoreListLikeThanMapLike(obj)) { | ||
return parent + '[]'; | ||
} | ||
if (typeReflections.isMapLike(obj)) { | ||
return parent + '{}'; | ||
} | ||
} | ||
} | ||
return undefined; | ||
} | ||
module.exports = { | ||
setName: setName, | ||
getName: getName | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/*can-reflect@1.17.6#reflections/get-set/get-set*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-symbol', | ||
'../type/type' | ||
], function (require, exports, module) { | ||
'use strict'; | ||
var canSymbol = require('can-symbol'); | ||
var typeReflections = require('../type/type'); | ||
var setKeyValueSymbol = canSymbol.for('can.setKeyValue'), getKeyValueSymbol = canSymbol.for('can.getKeyValue'), getValueSymbol = canSymbol.for('can.getValue'), setValueSymbol = canSymbol.for('can.setValue'); | ||
var reflections = { | ||
setKeyValue: function (obj, key, value) { | ||
if (typeReflections.isSymbolLike(key)) { | ||
if (typeof key === 'symbol') { | ||
obj[key] = value; | ||
} else { | ||
Object.defineProperty(obj, key, { | ||
enumerable: false, | ||
configurable: true, | ||
value: value, | ||
writable: true | ||
}); | ||
} | ||
return; | ||
} | ||
var setKeyValue = obj[setKeyValueSymbol]; | ||
if (setKeyValue !== undefined) { | ||
return setKeyValue.call(obj, key, value); | ||
} else { | ||
obj[key] = value; | ||
} | ||
}, | ||
getKeyValue: function (obj, key) { | ||
var getKeyValue = obj[getKeyValueSymbol]; | ||
if (getKeyValue) { | ||
return getKeyValue.call(obj, key); | ||
} | ||
return obj[key]; | ||
}, | ||
deleteKeyValue: function (obj, key) { | ||
var deleteKeyValue = obj[canSymbol.for('can.deleteKeyValue')]; | ||
if (deleteKeyValue) { | ||
return deleteKeyValue.call(obj, key); | ||
} | ||
delete obj[key]; | ||
}, | ||
getValue: function (value) { | ||
if (typeReflections.isPrimitive(value)) { | ||
return value; | ||
} | ||
var getValue = value[getValueSymbol]; | ||
if (getValue) { | ||
return getValue.call(value); | ||
} | ||
return value; | ||
}, | ||
setValue: function (item, value) { | ||
var setValue = item && item[setValueSymbol]; | ||
if (setValue) { | ||
return setValue.call(item, value); | ||
} else { | ||
throw new Error('can-reflect.setValue - Can not set value.'); | ||
} | ||
}, | ||
splice: function (obj, index, removing, adding) { | ||
var howMany; | ||
if (typeof removing !== 'number') { | ||
var updateValues = obj[canSymbol.for('can.updateValues')]; | ||
if (updateValues) { | ||
return updateValues.call(obj, index, removing, adding); | ||
} | ||
howMany = removing.length; | ||
} else { | ||
howMany = removing; | ||
} | ||
if (arguments.length <= 3) { | ||
adding = []; | ||
} | ||
var splice = obj[canSymbol.for('can.splice')]; | ||
if (splice) { | ||
return splice.call(obj, index, howMany, adding); | ||
} | ||
return [].splice.apply(obj, [ | ||
index, | ||
howMany | ||
].concat(adding)); | ||
}, | ||
addValues: function (obj, adding, index) { | ||
var add = obj[canSymbol.for('can.addValues')]; | ||
if (add) { | ||
return add.call(obj, adding, index); | ||
} | ||
if (Array.isArray(obj) && index === undefined) { | ||
return obj.push.apply(obj, adding); | ||
} | ||
return reflections.splice(obj, index, [], adding); | ||
}, | ||
removeValues: function (obj, removing, index) { | ||
var removeValues = obj[canSymbol.for('can.removeValues')]; | ||
if (removeValues) { | ||
return removeValues.call(obj, removing, index); | ||
} | ||
if (Array.isArray(obj) && index === undefined) { | ||
removing.forEach(function (item) { | ||
var index = obj.indexOf(item); | ||
if (index >= 0) { | ||
obj.splice(index, 1); | ||
} | ||
}); | ||
return; | ||
} | ||
return reflections.splice(obj, index, removing, []); | ||
} | ||
}; | ||
reflections.get = reflections.getKeyValue; | ||
reflections.set = reflections.setKeyValue; | ||
reflections['delete'] = reflections.deleteKeyValue; | ||
module.exports = reflections; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*can-reflect@1.17.6#reflections/helpers*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-symbol' | ||
], function (require, exports, module) { | ||
'use strict'; | ||
var canSymbol = require('can-symbol'); | ||
module.exports = { | ||
makeGetFirstSymbolValue: function (symbolNames) { | ||
var symbols = symbolNames.map(function (name) { | ||
return canSymbol.for(name); | ||
}); | ||
var length = symbols.length; | ||
return function getFirstSymbol(obj) { | ||
var index = -1; | ||
while (++index < length) { | ||
if (obj[symbols[index]] !== undefined) { | ||
return obj[symbols[index]]; | ||
} | ||
} | ||
}; | ||
}, | ||
hasLength: function (list) { | ||
var type = typeof list; | ||
if (type === 'string' || Array.isArray(list)) { | ||
return true; | ||
} | ||
var length = list && (type !== 'boolean' && type !== 'number' && 'length' in list) && list.length; | ||
return typeof list !== 'function' && (length === 0 || typeof length === 'number' && length > 0 && length - 1 in list); | ||
} | ||
}; | ||
}); |
Oops, something went wrong.