Skip to content

Commit

Permalink
Merge pull request #75 from canjs/can-util-removal
Browse files Browse the repository at this point in the history
get rid of can-util
  • Loading branch information
chasenlehara authored Jul 4, 2018
2 parents f3dd7cd + f8b67e8 commit 6e39bfe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
38 changes: 18 additions & 20 deletions can-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ var canEvent = require('can-event-queue/map/map');
var ObservationRecorder = require('can-observation-recorder');

var CID = require('can-cid');
var isPromise = require('can-util/js/is-promise/is-promise');
var makeArray = require('can-util/js/make-array/make-array');
var assign = require('can-util/js/assign/assign');
var types = require('can-types');
var each = require('can-util/js/each/each');
var canReflect = require('can-reflect');
var assign = require('can-assign');
var types = require('can-types');
var canSymbol = require('can-symbol');
var CIDMap = require("can-util/js/cid-map/cid-map");
var CIDMap = require("can-cid/map/map");


// Helpers for `observable` lists.
Expand Down Expand Up @@ -52,14 +49,14 @@ var List = Map.extend(
this.length = 0;
CID(this, ".map");
this._setupComputedProperties();
instances = instances || [];
instances = instances === undefined ? [] : canReflect.toArray(instances);
var teardownMapping;

if (isPromise(instances)) {
if (canReflect.isPromise(instances)) {
this.replace(instances);
} else {
teardownMapping = instances.length && mapHelpers.addToMap(instances, this);
this.push.apply(this, makeArray(instances || []));
this.push.apply(this, instances);
}

if (teardownMapping) {
Expand Down Expand Up @@ -168,7 +165,7 @@ var List = Map.extend(
return canReflect.serialize(this, CIDMap);
},
splice: function (index, howMany) {
var args = makeArray(arguments),
var args = canReflect.toArray(arguments),
added =[],
i, len, listIndex,
allSame = args.length > 2;
Expand Down Expand Up @@ -226,10 +223,10 @@ var List = Map.extend(
getArgs = function (args) {
return args[0] && Array.isArray(args[0]) ?
args[0] :
makeArray(args);
canReflect.toArray(args);
};
// Create `push`, `pop`, `shift`, and `unshift`
each({
canReflect.eachKey({
/**
* @function can-list.prototype.push push
* @parent can-list.prototype
Expand Down Expand Up @@ -348,7 +345,7 @@ each({
};
});

each({
canReflect.eachKey({
/**
* @function can-list.prototype.pop pop
* @parent can-list.prototype
Expand Down Expand Up @@ -534,7 +531,7 @@ assign(List.prototype, {
* ```
*/
reverse: function() {
var list = [].reverse.call(makeArray(this));
var list = [].reverse.call(canReflect.toArray(this));
return this.replace(list);
},

Expand Down Expand Up @@ -605,12 +602,12 @@ assign(List.prototype, {
MapType = this.constructor.Map;
// Go through each of the passed `arguments` and
// see if it is list-like, an array, or something else
each(arguments, function(arg) {
canReflect.each(arguments, function(arg) {
if((canReflect.isObservableLike(arg) && canReflect.isListLike(arg)) || Array.isArray(arg)) {
// If it is list-like we want convert to a JS array then
// pass each item of the array to serializeNonTypes
var arr = (canReflect.isObservableLike(arg) && canReflect.isListLike(arg)) ? makeArray(arg) : arg;
each(arr, function(innerArg) {
var arr = (canReflect.isObservableLike(arg) && canReflect.isListLike(arg)) ? canReflect.toArray(arg) : arg;
canReflect.each(arr, function(innerArg) {
serializeNonTypes(MapType, innerArg, args);
});
}
Expand All @@ -625,7 +622,7 @@ assign(List.prototype, {
// as well (We know it should be list-like), then
// concat with our passed in args, then pass it to
// list constructor to make it back into a list
return new this.constructor(Array.prototype.concat.apply(makeArray(this), args));
return new this.constructor(Array.prototype.concat.apply(canReflect.toArray(this), args));
},

/**
Expand Down Expand Up @@ -725,7 +722,7 @@ assign(List.prototype, {
* ```
*/
replace: function (newList) {
if (isPromise(newList)) {
if (canReflect.isPromise(newList)) {
if(this._promise) {
this._promise.__isCurrentPromise = false;
}
Expand All @@ -738,7 +735,8 @@ assign(List.prototype, {
}
});
} else {
this.splice.apply(this, [0, this.length].concat(makeArray(newList || [])));
newList = newList === undefined ? [] : canReflect.toArray(newList);
this.splice.apply(this, [0, this.length].concat(newList));
}

return this;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"npmAlgorithm": "flat"
},
"dependencies": {
"can-assign": "^1.1.1",
"can-cid": "^1.1.2",
"can-construct": "^3.2.1",
"can-event-queue": "<2.0.0",
Expand All @@ -44,7 +45,6 @@
"can-stache-key": "^1.0.0",
"can-symbol": "^1.4.1",
"can-types": "^1.1.0",
"can-util": "^3.10.12",
"can-compute": "^4.0.0",
"can-queues": "<2.0.0",
"can-map": "^4.0.0"
Expand Down

0 comments on commit 6e39bfe

Please sign in to comment.