Skip to content

Commit

Permalink
1.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
bmomberger-bitovi committed Oct 4, 2017
1 parent 5ec1bd7 commit 643c89b
Show file tree
Hide file tree
Showing 19 changed files with 3,223 additions and 0 deletions.
24 changes: 24 additions & 0 deletions dist/amd/can-reflect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*can-reflect@1.4.2#can-reflect*/
define(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 type = require('./reflections/type/type');
var namespace = require('can-namespace');
var reflect = {};
[
functionReflections,
getSet,
observe,
shape,
type
].forEach(function (reflections) {
for (var prop in reflections) {
reflect[prop] = reflections[prop];
}
});
require('./types/map');
require('./types/set');
module.exports = namespace.Reflect = reflect;
});
39 changes: 39 additions & 0 deletions dist/amd/reflections/call/call.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*can-reflect@1.4.2#reflections/call/call*/
define(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;
}
}
}
};
});
111 changes: 111 additions & 0 deletions dist/amd/reflections/get-set/get-set.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*can-reflect@1.4.2#reflections/get-set/get-set*/
define(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;
}
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;
});
25 changes: 25 additions & 0 deletions dist/amd/reflections/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*can-reflect@1.4.2#reflections/helpers*/
define(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;
var length = list && type !== 'boolean' && typeof list !== 'number' && 'length' in list && list.length;
return typeof list !== 'function' && (length === 0 || typeof length === 'number' && length > 0 && length - 1 in list);
}
};
});
56 changes: 56 additions & 0 deletions dist/amd/reflections/observe/observe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*can-reflect@1.4.2#reflections/observe/observe*/
define(function (require, exports, module) {
var canSymbol = require('can-symbol');
var slice = [].slice;
function makeFallback(symbolName, fallbackName) {
return function (obj, event, handler) {
var method = obj[canSymbol.for(symbolName)];
if (method !== undefined) {
return method.call(obj, event, handler);
}
return this[fallbackName].apply(this, arguments);
};
}
function makeErrorIfMissing(symbolName, errorMessage) {
return function (obj, arg1, arg2) {
var method = obj[canSymbol.for(symbolName)];
if (method !== undefined) {
return method.call(obj, arg1, arg2);
}
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'),
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'),
onEvent: function (obj, eventName, callback) {
if (obj) {
var onEvent = obj[canSymbol.for('can.onEvent')];
if (onEvent !== undefined) {
return onEvent.call(obj, eventName, callback);
} else if (obj.addEventListener) {
obj.addEventListener(eventName, callback);
}
}
},
offEvent: function (obj, eventName, callback) {
if (obj) {
var offEvent = obj[canSymbol.for('can.offEvent')];
if (offEvent !== undefined) {
return offEvent.call(obj, eventName, callback);
} else if (obj.removeEventListener) {
obj.removeEventListener(eventName, callback);
}
}
}
};
});
Loading

0 comments on commit 643c89b

Please sign in to comment.