Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IE11 fixes #55

Merged
merged 4 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
language: node_js
node_js: node
node_js: 10
dist: xenial
addons:
firefox: latest
sauce_connect: true
before_script:
- npm run http-server &
- sleep 2
script: npm run ci
services:
- xvfb
6 changes: 3 additions & 3 deletions compat/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var set = {
if(mutators[prop]) {
mutators[prop].push(value[prop]);
} else {
throw new Error("can-query-logic: This type of configuration is not supported. Please use can-query-logic directly.")
throw new Error("can-query-logic: This type of configuration is not supported. Please use can-query-logic directly.");
}

}
Expand Down Expand Up @@ -123,7 +123,7 @@ var set = {
var filter = data.filter || {};
if(hasKey(filter, {
"$ne": true,
"$in": function(val){ return val["$in"]; }
"$in": function(val){ return val.$in; }
})) {
return SET.UNDEFINABLE;
}
Expand Down Expand Up @@ -167,7 +167,7 @@ var set = {
return query;
}
}
}
};
},
props: {

Expand Down
26 changes: 13 additions & 13 deletions compat/prop_tests/sort_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ QUnit.test('set.isSubset with range', function(assert) {
// same
// right
// left
var addSort = function(set, value){
var addSort = function(set, value) {
set.sort = value;
};

var sort = {
left: function(setA, setB) {
left: function(setA) {
addSort(setA, "prop");
},
right: function(setA, setB) {
Expand All @@ -167,46 +167,46 @@ QUnit.test('set.isSubset with range', function(assert) {
};

var range = {
left: function(setA,setB){
left: function(setA) {
addRange(setA, 0,9);
},
right: function(setA,setB){
right: function(setA,setB) {
addRange(setB, 0,9);
},
same: function(setA,setB){
same: function(setA,setB) {
addRange(setA, 0,9);
addRange(setB, 0,9);
},
superLeft: function(setA,setB){
superLeft: function(setA,setB) {
addRange(setA, 0,9);
addRange(setB, 3,7);
},
superRight: function(setA,setB){
superRight: function(setA,setB) {
addRange(setB, 0,9);
addRange(setA, 3,7);
}
};

var sets = {
same: function(setA, setB){ },
superLeft: function(setA, setB){
same: function() { },
superLeft: function(setA, setB) {
setB.type = "apples";
},
superRight: function(setA, setB){
superRight: function(setA) {
setA.type = "apples";
}
};


var make = function(){
var make = function() {
var setA = {},
setB = {};
canReflect.eachIndex(arguments, function(method){
canReflect.eachIndex(arguments, function(method) {
method(setA, setB);
});
return {left: setA, right: setB};
};
var assertSubset = function(methods, result){
var assertSubset = function(methods, result) {
var sets = make.apply(null, methods);
assert.equal( algebra.isSubset(sets.left, sets.right), result, JSON.stringify(sets.left)+" ⊂ "+JSON.stringify(sets.right)+" = "+result );
};
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/date-string-example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {DefineMap, QueryLogic, Reflect as canReflect} from "can";
import {DefineMap, QueryLogic } from "can";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why a space at the end and not one at the beginning?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Find + replace mistake, fixed now.


class DateStringSet {
constructor(value){
Expand Down
3 changes: 1 addition & 2 deletions doc/examples/searchable-todo-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,4 @@ const result = queryLogic.filterMembers({
filter: {name: "important"}
}, todos);

console.log( todos ); //->[{id: 1, name: "important meeting"},{id: 3, name: "find out what important means"}]

console.log( result ); //->[{id: 1, name: "important meeting"},{id: 3, name: "find out what important means"}]
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"url": "donejs.com"
},
"scripts": {
"ci": "npm run test && node test-saucelabs.js",
"http-server": "http-server -p 3000 --silent",
"preversion": "npm test",
"postpublish": "git push --tags && git push",
"testee": "testee test.html --browsers firefox",
"test": "npm run jshint && npm run testee",
"jshint": "jshint ./*.js src/**.js --config",
"jshint": "jshint --config .jshintrc --exclude ./node_modules,./dist .",
"release:patch": "npm version patch && npm publish",
"release:minor": "npm version minor && npm publish",
"release:major": "npm version major && npm publish",
Expand Down Expand Up @@ -51,10 +53,12 @@
"devDependencies": {
"can-define": "^2.0.3",
"can-test-helpers": "^1.1.2",
"http-server": "^0.11.0",
"jshint": "^2.9.1",
"steal": "^2.2.1",
"steal-qunit": "^2.0.0",
"steal-tools": "^2.2.1",
"test-saucelabs": "^0.0.6",
"testee": "^0.9.0"
},
"license": "MIT"
Expand Down
4 changes: 2 additions & 2 deletions src/serializers/basic-query-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ QUnit.test("nested properties", function(assert) {

QUnit.test("$or with the same types unify into maybe", function(assert) {

var MaybeSet = makeMaybe([null])
var MaybeSet = makeMaybe([null]);

var converter = makeBasicQueryConvert({
identity: ["id"],
Expand Down Expand Up @@ -222,7 +222,7 @@ QUnit.test("basicquery with no sort", function(assert) {
});
var basicQuery = converter.hydrate(query);

var objs = [{id: 0}, {id: 2}]
var objs = [{id: 0}, {id: 2}];
var item = {id: 1};

var res = basicQuery.index(item, objs);
Expand Down
5 changes: 2 additions & 3 deletions src/serializers/comparisons-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var QUnit = require("steal-qunit");
var comparisons = require("./comparisons");
var canReflect = require("can-reflect");
var is = require("../types/comparisons");
var ValuesNot = require("../types/values-not");

QUnit.module("can-query-logic/serializers/comparisons");
Expand All @@ -15,7 +14,7 @@ QUnit.test("hydrate and serialize with custom types that work with operators", f
"can.serialize": function(){
return this.value;
}
})
});

var hydrated = comparisons.hydrate({$in: [1,2]}, function(value){
return new Type(value);
Expand All @@ -37,7 +36,7 @@ QUnit.test("unknown hydrator is called in all cases", function(assert) {
var hydrated = [];
var addToHydrated = function(value){
hydrated.push(value);
}
};

comparisons.hydrate({$in: [1,2]}, addToHydrated);
comparisons.hydrate("abc", addToHydrated);
Expand Down
55 changes: 29 additions & 26 deletions src/serializers/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ var is = require("../types/comparisons");
var Serializer = require("../serializer");
var canReflect = require("can-reflect");
var ValuesNot = require("../types/values-not");
var ValuesAnd = require("../types/values-and");

function makeNew(Constructor) {
return function(value){
return function(value) {
return new Constructor(value);
};
}
Expand All @@ -24,7 +23,7 @@ function addHydrateFromValues(key, hydrate) {
hydrateMap[key] = function(value, unknownHydrator) {
var clones = value[key];
if(unknownHydrator) {
clones = clones.map(function(value){
clones = clones.map(function(value) {
return unknownHydrator(value);
});
}
Expand All @@ -37,10 +36,10 @@ function addHydrateFromValues(key, hydrate) {
}

// https://docs.mongodb.com/manual/reference/operator/query-comparison/
addHydrateFrom("$eq", function(value){
addHydrateFrom("$eq", function(value) {
return new is.In([value]);
});
addHydrateFrom("$ne", function(value){
addHydrateFrom("$ne", function(value) {
return new is.NotIn([value]);
});

Expand All @@ -63,10 +62,10 @@ var oppositeTypeMap = {
NotIn: { Type: is.In, prop: "values" }
};

hydrateMap["$not"] = function(value, unknownHydrator) {
hydrateMap.$not = function(value, unknownHydrator) {
// Many nots can be hydrated to their opposite.
var hydratedValue = hydrateValue(value["$not"], unknownHydrator);
var typeName = hydratedValue.constructor.name;
var hydratedValue = hydrateValue(value.$not, unknownHydrator);
var typeName = hydratedValue.constructor.name || hydratedValue.constructor.toString().match(/^\s*function\s*(\S*)\s*\(/)[1];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a hack to get IE 11 working because constructor.name isn’t available.

I think we should probably fix canjs/can-reflect#167 and add a getConstructorName method to can-reflect that returns just the constructor name (instead of something like ConstructorName{}, which is what getName returns).

Otherwise, we could maybe refactor this code to not rely on the constructor name… I think that would be a lot more involved though because there’s a lot of functions involved with the hydrateValue() call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the problem with getName? I'm not sure I follow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that you can pass in a constructor function to getName and it’ll return just the name, not something like ConstructorName{}. Scratch what I said about adding a separate getConstructorName method.


if(oppositeTypeMap[typeName]) {
var options = oppositeTypeMap[typeName];
Expand All @@ -83,54 +82,58 @@ addHydrateFromValues("$nin", makeNew(is.NotIn));


var serializer = new Serializer([
[is.In,function(isIn, serialize){
[is.In,function(isIn, serialize) {
return isIn.values.length === 1 ?
serialize(isIn.values[0]) :
{$in: isIn.values.map(serialize)};
}],
[is.NotIn,function(notIn, serialize){
[is.NotIn,function(notIn, serialize) {
return notIn.values.length === 1 ?
{$ne: serialize(notIn.values[0])} : {$nin: notIn.values.map(serialize)};
}],
[is.GreaterThan, function(gt, serialize){ return {$gt: serialize(gt.value) }; }],
[is.GreaterThanEqual, function(gte, serialize){ return {$gte: serialize(gte.value) }; }],
[is.LessThan, function(lt, serialize){ return {$lt: serialize(lt.value) }; }],
[is.LessThanEqual, function(lt, serialize){ return {$lte: serialize(lt.value) }; }],
[is.And, function(and, serialize){
[is.GreaterThan, function(gt, serialize) { return {$gt: serialize(gt.value) }; }],
[is.GreaterThanEqual, function(gte, serialize) { return {$gte: serialize(gte.value) }; }],
[is.LessThan, function(lt, serialize) { return {$lt: serialize(lt.value) }; }],
[is.LessThanEqual, function(lt, serialize) { return {$lte: serialize(lt.value) }; }],
[is.And, function(and, serialize) {
var obj = {};
and.values.forEach(function(clause){
and.values.forEach(function(clause) {
canReflect.assignMap(obj, serialize(clause) );
});
return obj;
}],
[is.All, function(all, serialize) { return {$all: serialize(all.values)}}]
/*[is.Or, function(or, serialize){
[is.All, function(all, serialize) {
return {
$or: or.values.map(function(value){
$all: serialize(all.values)
};
}]
/*[is.Or, function(or, serialize) {
return {
$or: or.values.map(function(value) {
return serialize(value, serialize);
})
};
}]*/
]);

function hydrateValue(value, hydrateUnknown){
function hydrateValue(value, hydrateUnknown) {
if(!hydrateUnknown) {
hydrateUnknown = function(){
hydrateUnknown = function() {
throw new Error("can-query-logic doesn't recognize operator: "+JSON.stringify(value));
}
};
}
if(Array.isArray(value)) {
return new is.In(value.map(function(value){
return new is.In(value.map(function(value) {
return hydrateUnknown(value);
}));
}
else if(value && typeof value === "object") {
var keys = Object.keys(value);
var allKeysAreComparisons = keys.every(function(key){
return hydrateMap[key]
var allKeysAreComparisons = keys.every(function(key) {
return hydrateMap[key];
});
if(allKeysAreComparisons) {
var andClauses = keys.map(function(key){
var andClauses = keys.map(function(key) {
var part = {};
part[key] = value[key];
var hydrator = hydrateMap[key];
Expand Down
4 changes: 2 additions & 2 deletions src/types/array-comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ comparisons.All.test = function(allValues, recordValues) {
function makeThrowCannotCompare(type, left, right) {
return function() {
throw new Error("can-query-logic: Cannot perform " + type + " between " + left + " and " + right);
}
};
}

function throwComparatorAllTypes(type1, type2) {
Expand Down Expand Up @@ -73,7 +73,7 @@ var comparators = {
And_All: throwComparatorAllTypes("And", "All"),
All_Or: throwComparatorDifference("All", "Or"),
Or_All: throwComparatorAllTypes("Or", "All")
}
};

exports.comparisons = comparisons;
exports.comparators = comparators;
6 changes: 4 additions & 2 deletions src/types/basic-query-filter-from-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ QUnit.test("returns undefined against incompatible set", function(assert) {
var fromQuery = new BasicQuery({
filter: new BasicQuery.KeysAnd({ type: 'critical' })
});
var res;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the indenting is off here. Also the next line could be try { (with a space) while you're fixing this up elsewhere.

try{
var res = query.filterFrom(items, fromQuery);
res = query.filterFrom(items, fromQuery);
} catch(e) {
assert.ok(true, "throws an error")
assert.ok(true, "throws an error");
}
assert.notOk(res, "did not throw an error");
});
2 changes: 1 addition & 1 deletion src/types/basic-query-merge-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ QUnit.test("unionMembers filters for uniqueness", function(assert) {
assert.deepEqual(union, unionItems);

// BREAK
var union = b.merge(a,bItems,aItems, getId );
union = b.merge(a,bItems,aItems, getId );
assert.deepEqual(union, unionItems);

});
3 changes: 1 addition & 2 deletions src/types/basic-query-sorting-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@ QUnit.test('rangeInclusive legacyUnion', function(assert) {
*
* X U Y = X
*/
res = legacyUnion({}, { start: 0, end: 10 });
var res = legacyUnion({}, { start: 0, end: 10 });
assert.deepEqual(res, {}, "universal set");
return;
/*
* X = [A100, ..., A199]
* Y = [A200, ..., A299]
Expand Down
5 changes: 2 additions & 3 deletions src/types/basic-query-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var BasicQuery = require("./basic-query");
var canSymbol = require("can-symbol");
var QUnit = require("steal-qunit");
var KeysAnd = require("./keys-and");
var ValuesAnd = require("./values-and");
Expand All @@ -9,7 +8,7 @@ QUnit.module("can-query-logic/types/basic-query filterMembersAndGetCount");
QUnit.test("Able to filter on a universal set", function(assert) {
var parent = new BasicQuery({
filter: new KeysAnd({})
})
});
var bData = [{},{}];

var FooType = function(value) { this.value = value; };
Expand All @@ -30,7 +29,7 @@ QUnit.test("Able to filter on a universal set", function(assert) {
QUnit.test("Page is a universal set", function(assert) {
var parent = new BasicQuery({
filter: new KeysAnd({})
})
});
var bData = [{},{}];

var FooType = function(value) { this.value = value; };
Expand Down
Loading