-
Notifications
You must be signed in to change notification settings - Fork 2
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
IE11 fixes #55
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
}; | ||
} | ||
|
@@ -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); | ||
}); | ||
} | ||
|
@@ -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]); | ||
}); | ||
|
||
|
@@ -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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a hack to get IE 11 working because I think we should probably fix canjs/can-reflect#167 and add a 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain the problem with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just realized that you can pass in a constructor function to |
||
|
||
if(oppositeTypeMap[typeName]) { | ||
var options = oppositeTypeMap[typeName]; | ||
|
@@ -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]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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{ | ||
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"); | ||
}); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.