-
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
1 parent
ce3a8a0
commit 5e37e7d
Showing
23 changed files
with
4,296 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,42 @@ | ||
/*can-reflect@1.16.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) { | ||
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,45 @@ | ||
/*can-reflect@1.16.6#reflections/call/call*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-symbol', | ||
'../type/type' | ||
], function (require, exports, module) { | ||
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,53 @@ | ||
/*can-reflect@1.16.6#reflections/get-name/get-name*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-symbol', | ||
'../type/type' | ||
], function (require, exports, module) { | ||
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 }); | ||
} | ||
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') { | ||
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,120 @@ | ||
/*can-reflect@1.16.6#reflections/get-set/get-set*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-symbol', | ||
'../type/type' | ||
], function (require, exports, module) { | ||
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,33 @@ | ||
/*can-reflect@1.16.6#reflections/helpers*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-symbol' | ||
], function (require, exports, module) { | ||
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); | ||
} | ||
}; | ||
}); |
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,95 @@ | ||
/*can-reflect@1.16.6#reflections/observe/observe*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-symbol' | ||
], function (require, exports, module) { | ||
var canSymbol = require('can-symbol'); | ||
var slice = [].slice; | ||
function makeFallback(symbolName, fallbackName) { | ||
return function (obj, event, handler, queueName) { | ||
var method = obj[canSymbol.for(symbolName)]; | ||
if (method !== undefined) { | ||
return method.call(obj, event, handler, queueName); | ||
} | ||
return this[fallbackName].apply(this, arguments); | ||
}; | ||
} | ||
function makeErrorIfMissing(symbolName, errorMessage) { | ||
return function (obj) { | ||
var method = obj[canSymbol.for(symbolName)]; | ||
if (method !== undefined) { | ||
var args = slice.call(arguments, 1); | ||
return method.apply(obj, args); | ||
} | ||
throw new Error(errorMessage); | ||
}; | ||
} | ||
module.exports = { | ||
onKeyValue: makeFallback('can.onKeyValue', 'onEvent'), | ||
offKeyValue: makeFallback('can.offKeyValue', 'offEvent'), | ||
onKeys: makeErrorIfMissing('can.onKeys', 'can-reflect: can not observe an onKeys event'), | ||
onKeysAdded: makeErrorIfMissing('can.onKeysAdded', 'can-reflect: can not observe an onKeysAdded event'), | ||
onKeysRemoved: makeErrorIfMissing('can.onKeysRemoved', 'can-reflect: can not unobserve an onKeysRemoved event'), | ||
getKeyDependencies: makeErrorIfMissing('can.getKeyDependencies', 'can-reflect: can not determine dependencies'), | ||
getWhatIChange: makeErrorIfMissing('can.getWhatIChange', 'can-reflect: can not determine dependencies'), | ||
getChangesDependencyRecord: function getChangesDependencyRecord(handler) { | ||
var fn = handler[canSymbol.for('can.getChangesDependencyRecord')]; | ||
if (typeof fn === 'function') { | ||
return fn(); | ||
} | ||
}, | ||
keyHasDependencies: makeErrorIfMissing('can.keyHasDependencies', 'can-reflect: can not determine if this has key dependencies'), | ||
onValue: makeErrorIfMissing('can.onValue', 'can-reflect: can not observe value change'), | ||
offValue: makeErrorIfMissing('can.offValue', 'can-reflect: can not unobserve value change'), | ||
getValueDependencies: makeErrorIfMissing('can.getValueDependencies', 'can-reflect: can not determine dependencies'), | ||
valueHasDependencies: makeErrorIfMissing('can.valueHasDependencies', 'can-reflect: can not determine if value has dependencies'), | ||
onPatches: makeErrorIfMissing('can.onPatches', 'can-reflect: can not observe patches on object'), | ||
offPatches: makeErrorIfMissing('can.offPatches', 'can-reflect: can not unobserve patches on object'), | ||
onInstancePatches: makeErrorIfMissing('can.onInstancePatches', 'can-reflect: can not observe onInstancePatches on Type'), | ||
offInstancePatches: makeErrorIfMissing('can.offInstancePatches', 'can-reflect: can not unobserve onInstancePatches on Type'), | ||
onInstanceBoundChange: makeErrorIfMissing('can.onInstanceBoundChange', 'can-reflect: can not observe bound state change in instances.'), | ||
offInstanceBoundChange: makeErrorIfMissing('can.offInstanceBoundChange', 'can-reflect: can not unobserve bound state change'), | ||
isBound: makeErrorIfMissing('can.isBound', 'can-reflect: cannot determine if object is bound'), | ||
onEvent: function (obj, eventName, callback, queue) { | ||
if (obj) { | ||
var onEvent = obj[canSymbol.for('can.onEvent')]; | ||
if (onEvent !== undefined) { | ||
return onEvent.call(obj, eventName, callback, queue); | ||
} else if (obj.addEventListener) { | ||
obj.addEventListener(eventName, callback, queue); | ||
} | ||
} | ||
}, | ||
offEvent: function (obj, eventName, callback, queue) { | ||
if (obj) { | ||
var offEvent = obj[canSymbol.for('can.offEvent')]; | ||
if (offEvent !== undefined) { | ||
return offEvent.call(obj, eventName, callback, queue); | ||
} else if (obj.removeEventListener) { | ||
obj.removeEventListener(eventName, callback, queue); | ||
} | ||
} | ||
}, | ||
setPriority: function (obj, priority) { | ||
if (obj) { | ||
var setPriority = obj[canSymbol.for('can.setPriority')]; | ||
if (setPriority !== undefined) { | ||
setPriority.call(obj, priority); | ||
return true; | ||
} | ||
} | ||
return false; | ||
}, | ||
getPriority: function (obj) { | ||
if (obj) { | ||
var getPriority = obj[canSymbol.for('can.getPriority')]; | ||
if (getPriority !== undefined) { | ||
return getPriority.call(obj); | ||
} | ||
} | ||
return undefined; | ||
} | ||
}; | ||
}); |
Oops, something went wrong.