Skip to content

Commit dd84ece

Browse files
committed
removing functions added by can-event-queue from LetContext.prototype
1 parent 28b3661 commit dd84ece

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

can-view-scope.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var canReflect = require("can-reflect");
1818
var canLog = require('can-log/dev/dev');
1919
var defineLazyValue = require('can-define-lazy-value');
2020
var stacheHelpers = require('can-stache-helpers');
21-
var SimpleMap = require('can-simple-map');
21+
var LetContext = require('./let-context');
2222

2323

2424
// ## Helpers
@@ -30,10 +30,6 @@ function returnFalse(){
3030
return false;
3131
}
3232

33-
// ### LetContext
34-
// Instances of this are used to create a `let` variable context.
35-
var LetContext = SimpleMap.extend("LetContext",{});
36-
3733
// ## Scope
3834
// Represents a node in the scope tree.
3935
function Scope(context, parent, meta) {

let-context.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var SimpleMap = require('can-simple-map');
2+
3+
// ### LetContext
4+
// Instances of this are used to create a `let` variable context.
5+
6+
// Like Object.create, but only keeps Symbols and properties in `propertiesToKeep`
7+
function objectCreateWithSymbolsAndSpecificProperties(obj, propertiesToKeep) {
8+
var newObj = {};
9+
10+
// copy over all Symbols from obj
11+
if ("getOwnPropertySymbols" in Object) {
12+
Object.getOwnPropertySymbols(obj).forEach(function(key) {
13+
newObj[key] = obj[key];
14+
});
15+
}
16+
17+
// copy over specific properties from obj (also fake Symbols properties for IE support);
18+
Object.getOwnPropertyNames(obj).forEach(function(key) {
19+
if (propertiesToKeep.indexOf(key) >= 0 || key.indexOf("@@symbol") === 0) {
20+
newObj[key] = obj[key];
21+
}
22+
});
23+
24+
return Object.create(newObj);
25+
}
26+
27+
var LetContext = SimpleMap.extend("LetContext", {});
28+
LetContext.prototype = objectCreateWithSymbolsAndSpecificProperties(SimpleMap.prototype, [
29+
// SimpleMap properties
30+
"setup",
31+
"attr",
32+
"serialize",
33+
"get",
34+
"set",
35+
"log",
36+
// required by SimpleMap properties
37+
"dispatch",
38+
// Construct properties (not added by can-event-queue)
39+
"constructorExtends",
40+
"newInstance",
41+
"_inherit",
42+
"_defineProperty",
43+
"_overwrite",
44+
"instance",
45+
"extend",
46+
"ReturnValue",
47+
"setup",
48+
"init"
49+
]);
50+
LetContext.prototype.constructor = LetContext;
51+
52+
module.exports = LetContext;

test/scope-test.js

+8
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,15 @@ QUnit.test("able to read partials", function(assert) {
13791379
var result = scope.get("myPartial");
13801380

13811381
assert.equal(result, myPartial, "read the value");
1382+
});
1383+
1384+
QUnit.test("properties can shadow functions on can-event-queue/map when there is a LetContext", function(assert) {
1385+
var scope = new Scope({
1386+
one: "the one property"
1387+
})
1388+
.addLetContext();
13821389

1390+
assert.equal(scope.get("one"), "the one property", "read the value");
13831391
});
13841392

13851393
require("./variable-scope-test");

0 commit comments

Comments
 (0)