From 4bca14a1794446c03e876cb1d9ee6dc4ba2dfd3a Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Sat, 7 Oct 2017 20:12:27 -0500 Subject: [PATCH 01/36] uses queues --- .npmrc | 1 + can-stache-key-test.js | 66 +++++++++++++++--------------------------- package.json | 38 +++++++----------------- 3 files changed, 35 insertions(+), 70 deletions(-) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/can-stache-key-test.js b/can-stache-key-test.js index 0fcd04e..c5a6d37 100644 --- a/can-stache-key-test.js +++ b/can-stache-key-test.js @@ -1,24 +1,17 @@ var observeReader = require("can-stache-key"); var QUnit = require('steal-qunit'); var Observation = require('can-observation'); -var canEvent = require('can-event'); +var eventQueue = require('can-event-queue'); var dev = require('can-util/js/dev/dev'); -var assign = require("can-util/js/assign/assign"); -var eventAsync = require("can-event/async/async"); var SimpleMap = require("can-simple-map"); var canReflect = require("can-reflect"); -QUnit.module('can-observation/reader',{ - setup: function(){ - eventAsync.sync(); - }, - teardown: function(){ - eventAsync.async(); - } +QUnit.module('can-stache-key',{ + }); -test("can.Compute.read can read a promise (#179)", function(){ +test("can read a promise (#179)", function(){ var data = { promise: new Promise(function(resolve){ setTimeout(function(){ @@ -29,16 +22,14 @@ test("can.Compute.read can read a promise (#179)", function(){ var calls = 0; var c = new Observation(function(){ return observeReader.read(data,observeReader.reads("promise.value")).value; - }, null, { - updater: function(newVal, oldVal){ - calls++; - equal(calls, 1, "only one call"); - equal(newVal, "Something", "new value"); - equal(oldVal, undefined, "oldVal"); - start(); - } }); - c.start(); + canReflect.onValue(c, function(newVal, oldVal){ + calls++; + equal(calls, 1, "only one call"); + equal(newVal, "Something", "new value"); + equal(oldVal, undefined, "oldVal"); + start(); + }) stop(); @@ -57,16 +48,14 @@ test("can.Compute.read can read a promise-like (#82)", function(){ var calls = 0; var c = new Observation(function(){ return observeReader.read(data,observeReader.reads("promiseLike.value")).value; - }, null, { - updater: function(newVal, oldVal){ - calls++; - equal(calls, 1, "only one call"); - equal(newVal, "Something", "new value"); - equal(oldVal, undefined, "oldVal"); - start(); - } }); - c.start(); + canReflect.onValue(c, function(newVal, oldVal){ + calls++; + equal(calls, 1, "only one call"); + equal(newVal, "Something", "new value"); + equal(oldVal, undefined, "oldVal"); + start(); + }); stop(); @@ -88,7 +77,7 @@ test('can.compute.reads', function(){ }); test('able to read things like can-define', 3, function(){ - var obj = assign({}, canEvent); + var obj = eventQueue({}); var prop = "PROP"; Object.defineProperty(obj, "prop",{ get: function(){ @@ -113,14 +102,8 @@ test('able to read things like can-define', 3, function(){ } }).value; equal(value, "PROP"); - }, null, { - updater: function(){ - - } }); - c.start(); - - + canReflect.onValue(c, function(){}); }); test("foundObservable called with observable object (#7)", function(){ @@ -138,9 +121,8 @@ test("foundObservable called with observable object (#7)", function(){ QUnit.equal(obs, map); } }); - }, null,{}); - c.start(); - + }); + canReflect.onValue(c, function(){}); }); test("can read from strings", function(){ @@ -159,10 +141,10 @@ test("read / write to DefineMap", function(){ } }); return data.value; - }, null,function(newVal){ + }); + canReflect.onValue(c, function(newVal){ QUnit.equal(newVal, 1, "got updated"); }); - c.start(); observeReader.write(map,"value",1); }); diff --git a/package.json b/package.json index efc0941..d967338 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "0.1.0", + "version": "1.0.0-pre.0", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { @@ -13,9 +13,8 @@ "url": "http://donejs.com" }, "scripts": { - "preversion": "npm test && npm run build", - "version": "git commit -am \"Update version number\" && git checkout -b release && git add -f dist/", - "postpublish": "git push --tags && git checkout master && git branch -D release && git push", + "preversion": "npm test", + "postpublish": "git push --tags && git push", "testee": "testee test.html --browsers firefox", "test": "npm run detect-cycle && npm run jshint && npm run testee", "jshint": "jshint ./*.js --config", @@ -26,23 +25,10 @@ "develop": "done-serve --static --develop --port 8080", "detect-cycle": "detect-cyclic-packages --ignore done-serve" }, - "main": "dist/cjs/can-stache-key", - "browser": { - "transform": [ - "cssify" - ] - }, - "browserify": { - "transform": [ - "cssify" - ] - }, + "main": "can-stache-key", "keywords": [ - "Done", - "JS", - "Can", - "JS", - "donejs-plugin" + "DoneJS", + "CanJS" ], "steal": { "main": "can-stache-key", @@ -54,24 +40,20 @@ "generator-donejs", "donejs-cli", "steal-tools" - ], - "plugins": [ - "steal-less", - "steal-stache" ] }, "dependencies": { "can-cid": "^1.0.0", - "can-event": "^3.5.0", "can-namespace": "1.0.0", "can-reflect": "^1.1.0", - "can-reflect-promise": "^1.1.0", + "can-reflect-promise": "^2.0.0-pre.2", "can-symbol": "^1.0.0", "can-util": "^3.9.0", - "can-observation": "^3.3.0" + "can-observation": "^4.0.0-pre.2" }, "devDependencies": { - "can-simple-map": "^3.3.0", + "can-event-queue": "^0.1.1", + "can-simple-map": "^4.0.0-pre.0", "detect-cyclic-packages": "^1.1.0", "jshint": "^2.9.1", "steal": "^1.3.1", From ca8e5d9b9f51d1357cf259364ce4ef3ab4e580d8 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Sat, 7 Oct 2017 20:13:09 -0500 Subject: [PATCH 02/36] linting --- can-stache-key-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can-stache-key-test.js b/can-stache-key-test.js index c5a6d37..a637535 100644 --- a/can-stache-key-test.js +++ b/can-stache-key-test.js @@ -29,7 +29,7 @@ test("can read a promise (#179)", function(){ equal(newVal, "Something", "new value"); equal(oldVal, undefined, "oldVal"); start(); - }) + }); stop(); From 4731a0a1095858b62132ecdea6825f4366044d48 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Sat, 7 Oct 2017 20:14:19 -0500 Subject: [PATCH 03/36] adding pre script --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index d967338..193c9f1 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "testee": "testee test.html --browsers firefox", "test": "npm run detect-cycle && npm run jshint && npm run testee", "jshint": "jshint ./*.js --config", + "release:pre": "npm version prerelease && npm publish --tag pre", "release:patch": "npm version patch && npm publish", "release:minor": "npm version minor && npm publish", "release:major": "npm version major && npm publish", From a36da700dc4a0598b5dbbe143f6531d3f206e200 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Sat, 7 Oct 2017 20:14:35 -0500 Subject: [PATCH 04/36] 1.0.0-pre.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 193c9f1..75dd1f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.0", + "version": "1.0.0-pre.1", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From 31472ec04a30fa8ad0fc92f9227a66e46922d3a6 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Sat, 7 Oct 2017 21:15:43 -0500 Subject: [PATCH 05/36] reads props correctly --- can-stache-key.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/can-stache-key.js b/can-stache-key.js index c1a38a5..a287b9d 100644 --- a/can-stache-key.js +++ b/can-stache-key.js @@ -10,6 +10,7 @@ var getValueSymbol = canSymbol.for("can.getValue"); var setValueSymbol = canSymbol.for("can.setValue"); var isValueLikeSymbol = canSymbol.for("can.isValueLike"); +var peek = Observation.ignore(canReflect.getKeyValue.bind(canReflect)); var observeReader; var isAt = function(index, reads) { var prevRead = reads[index-1]; @@ -285,11 +286,12 @@ observeReader = { } else { last = keys[0]; } + var keyValue = peek(parent, last.key); // here's where we need to figure out the best way to write // if property being set points at a compute, set the compute - if( observeReader.valueReadersMap.isValueLike.test(parent[last.key], keys.length - 1, keys, options) ) { - observeReader.valueReadersMap.isValueLike.write(parent[last.key], value, options); + if( observeReader.valueReadersMap.isValueLike.test(keyValue, keys.length - 1, keys, options) ) { + observeReader.valueReadersMap.isValueLike.write(keyValue, value, options); } else { if(observeReader.valueReadersMap.isValueLike.test(parent, keys.length - 1, keys, options) ) { parent = parent[getValueSymbol](); From 08c93296558259da0e26368063b2cca26009e0c3 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Sat, 7 Oct 2017 21:16:01 -0500 Subject: [PATCH 06/36] 1.0.0-pre.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 75dd1f5..e1e3c80 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.1", + "version": "1.0.0-pre.2", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From ef7de3b675f1e94a477e3abc80cc10d076c4bf7c Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 19 Oct 2017 21:08:26 -0500 Subject: [PATCH 07/36] able to write simple observables --- can-stache-key-test.js | 13 +++++++++++++ can-stache-key.js | 12 +++++++++++- package.json | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/can-stache-key-test.js b/can-stache-key-test.js index a637535..3e46673 100644 --- a/can-stache-key-test.js +++ b/can-stache-key-test.js @@ -3,6 +3,7 @@ var QUnit = require('steal-qunit'); var Observation = require('can-observation'); var eventQueue = require('can-event-queue'); var dev = require('can-util/js/dev/dev'); +var SimpleObservable = require("can-simple-observable"); var SimpleMap = require("can-simple-map"); var canReflect = require("can-reflect"); @@ -237,3 +238,15 @@ test("it returns null when promise getter is null #2", function(){ var nullPromise = observeReader.read(null, observeReader.reads('value')); QUnit.equal(typeof nullPromise,"object"); }); + +QUnit.test("set onto observable objects and values", function(){ + var map = new SimpleMap(); + observeReader.write({map: map},"map", {a: "b"}); + + QUnit.equal(map.get("a"), "b", "merged"); + + + var simple = new SimpleObservable(); + observeReader.write({simple: simple},"simple", 1); + QUnit.equal(simple.get(), 1); +}); diff --git a/can-stache-key.js b/can-stache-key.js index a287b9d..7a84b47 100644 --- a/can-stache-key.js +++ b/can-stache-key.js @@ -234,7 +234,17 @@ observeReader = { } }, write: function(base, prop, newVal){ - base[prop] = newVal; + var propValue = base[prop]; + // if newVal is observable object, lets try to update + if(canReflect.isMapLike(propValue) && newVal && typeof newVal === "object") { + dev.warn("can-stache-key: Merging data into \"" + prop + "\" because its parent is non-observable"); + canReflect.update(propValue, newVal) + } else if(canReflect.isValueLike(propValue)){ + canReflect.setValue(propValue, newVal); + } else { + base[prop] = newVal; + } + } } ], diff --git a/package.json b/package.json index e1e3c80..8d762b6 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "devDependencies": { "can-event-queue": "^0.1.1", "can-simple-map": "^4.0.0-pre.0", + "can-simple-observable": "^2.0.0-pre.11", "detect-cyclic-packages": "^1.1.0", "jshint": "^2.9.1", "steal": "^1.3.1", From c41f74a3df604eb04aa5fefb741d1334f4d80ca8 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 19 Oct 2017 21:09:13 -0500 Subject: [PATCH 08/36] lint --- can-stache-key.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can-stache-key.js b/can-stache-key.js index 7a84b47..15d68b5 100644 --- a/can-stache-key.js +++ b/can-stache-key.js @@ -238,7 +238,7 @@ observeReader = { // if newVal is observable object, lets try to update if(canReflect.isMapLike(propValue) && newVal && typeof newVal === "object") { dev.warn("can-stache-key: Merging data into \"" + prop + "\" because its parent is non-observable"); - canReflect.update(propValue, newVal) + canReflect.update(propValue, newVal); } else if(canReflect.isValueLike(propValue)){ canReflect.setValue(propValue, newVal); } else { From 729e9875887176c65b45d9c250df464a30ed9acc Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 19 Oct 2017 21:09:27 -0500 Subject: [PATCH 09/36] 1.0.0-pre.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8d762b6..e10d902 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.2", + "version": "1.0.0-pre.3", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From 7b01b6ab88c425e4dd1bccc94f7c9c0439264697 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 19 Oct 2017 21:12:10 -0500 Subject: [PATCH 10/36] check if observable --- can-stache-key.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can-stache-key.js b/can-stache-key.js index 15d68b5..1432876 100644 --- a/can-stache-key.js +++ b/can-stache-key.js @@ -239,7 +239,7 @@ observeReader = { if(canReflect.isMapLike(propValue) && newVal && typeof newVal === "object") { dev.warn("can-stache-key: Merging data into \"" + prop + "\" because its parent is non-observable"); canReflect.update(propValue, newVal); - } else if(canReflect.isValueLike(propValue)){ + } else if(canReflect.isValueLike(propValue) && canReflect.isObservableLike(propValue)){ canReflect.setValue(propValue, newVal); } else { base[prop] = newVal; From 0de00f98bb3b96ae64ac6702e4a23476cba7accd Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 19 Oct 2017 21:12:20 -0500 Subject: [PATCH 11/36] 1.0.0-pre.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e10d902..bbb61ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.3", + "version": "1.0.0-pre.4", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From d6155b446577272efcf17241b2f9cf0d409f628b Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 19 Oct 2017 21:15:14 -0500 Subject: [PATCH 12/36] 1.0.0-pre.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bbb61ff..ad992b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.4", + "version": "1.0.0-pre.5", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From 61e34611ba184ec24da36ffdbe71b5f83829fb90 Mon Sep 17 00:00:00 2001 From: Christopher Baker Date: Thu, 26 Oct 2017 16:02:20 -0700 Subject: [PATCH 13/36] cleanup dependencies --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index ad992b1..cebfa8d 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ ] }, "dependencies": { - "can-cid": "^1.0.0", "can-namespace": "1.0.0", "can-reflect": "^1.1.0", "can-reflect-promise": "^2.0.0-pre.2", From 7ef59395600592841c6a968b72b9f54ab8adc2f0 Mon Sep 17 00:00:00 2001 From: Christopher Baker Date: Thu, 26 Oct 2017 17:39:22 -0700 Subject: [PATCH 14/36] 1.0.0-pre.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cebfa8d..265e18e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.5", + "version": "1.0.0-pre.6", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From 9380651a6ee9e70add044fc50fb2d35c8a70a677 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 26 Oct 2017 21:31:21 -0500 Subject: [PATCH 15/36] tolerate wider event-queue --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 265e18e..0aa51b6 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "can-observation": "^4.0.0-pre.2" }, "devDependencies": { - "can-event-queue": "^0.1.1", + "can-event-queue": "<2.0.0", "can-simple-map": "^4.0.0-pre.0", "can-simple-observable": "^2.0.0-pre.11", "detect-cyclic-packages": "^1.1.0", From aee30f0bd5ed5f36a8034b98ebcd17651503e2d5 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 26 Oct 2017 21:31:39 -0500 Subject: [PATCH 16/36] 1.0.0-pre.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0aa51b6..6407a41 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.6", + "version": "1.0.0-pre.7", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From f056cbfc96d07e0653e2229975966f69d2381689 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 26 Oct 2017 22:34:38 -0500 Subject: [PATCH 17/36] protect tests --- can-stache-key-test.js | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/can-stache-key-test.js b/can-stache-key-test.js index 3e46673..e31effa 100644 --- a/can-stache-key-test.js +++ b/can-stache-key-test.js @@ -194,29 +194,30 @@ test("write to a map in a compute", function(){ QUnit.equal(map.attr("complete"), false, "value set"); }); +if(System.env.indexOf("production") < 0) { + test("promise readers throw errors (#70)", function() { + expect(1); + var oldError = dev.error; + dev.error = function() { + dev.error = oldError; + ok(true); + start(); + }; + + var promise = new Promise(function(resolve, reject) { + setTimeout(function() { + reject("Something"); + }, 0); + }); -test("promise readers throw errors (#70)", function() { - expect(1); - var oldError = dev.error; - dev.error = function() { - dev.error = oldError; - ok(true); - start(); - }; + var c = new Observation(function() { + return observeReader.read(promise, observeReader.reads("value"), {}).value; + }, null, { updater: function() {} }); - var promise = new Promise(function(resolve, reject) { - setTimeout(function() { - reject("Something"); - }, 0); + c.start(); + stop(); }); - - var c = new Observation(function() { - return observeReader.read(promise, observeReader.reads("value"), {}).value; - }, null, { updater: function() {} }); - - c.start(); - stop(); -}); +} QUnit.test("reads can be passed a number (can-stache#207)", function(){ var reads = observeReader.reads(0); From cb645141f8709304b6336a5178815c93b6a50fc4 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 26 Oct 2017 22:34:49 -0500 Subject: [PATCH 18/36] 1.0.0-pre.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6407a41..0a498d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.7", + "version": "1.0.0-pre.8", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From d2628ba90195ef544cb718c294aff5f2c9a86d31 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Fri, 27 Oct 2017 17:18:19 -0500 Subject: [PATCH 19/36] nice names for bound methods --- can-stache-key.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/can-stache-key.js b/can-stache-key.js index 1432876..97dc325 100644 --- a/can-stache-key.js +++ b/can-stache-key.js @@ -12,6 +12,18 @@ var setValueSymbol = canSymbol.for("can.setValue"); var isValueLikeSymbol = canSymbol.for("can.isValueLike"); var peek = Observation.ignore(canReflect.getKeyValue.bind(canReflect)); var observeReader; + +var bindName = Function.prototype.bind; +//!steal-remove-start +bindName = function(source){ + var fn = Function.prototype.bind.call(this, source); + Object.defineProperty(fn, "name", { + value: canReflect.getName(source) + "."+canReflect.getName(this), + }); + return fn; +} +//!steal-remove-end + var isAt = function(index, reads) { var prevRead = reads[index-1]; return prevRead && prevRead.at; @@ -147,13 +159,13 @@ observeReader = { }, read: function(value, i, reads, options, state, prev){ if( isAt(i, reads) ) { - return i === reads.length ? value.bind(prev) : value; + return i === reads.length ? bindName.call(value, prev) : value; } else if(options.callMethodsOnObservables && canReflect.isObservableLike(prev) && canReflect.isMapLike(prev)) { return value.apply(prev, options.args || []); } else if ( options.isArgument && i === reads.length ) { - return options.proxyMethods !== false ? value.bind(prev) : value; + return options.proxyMethods !== false ? bindName.call(value, prev) : value; } return value.apply(prev, options.args || []); } From 485a6e79e5a263089780e220ab6ed13a08418451 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Fri, 27 Oct 2017 17:18:58 -0500 Subject: [PATCH 20/36] lint --- can-stache-key.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/can-stache-key.js b/can-stache-key.js index 97dc325..82560d9 100644 --- a/can-stache-key.js +++ b/can-stache-key.js @@ -18,10 +18,10 @@ var bindName = Function.prototype.bind; bindName = function(source){ var fn = Function.prototype.bind.call(this, source); Object.defineProperty(fn, "name", { - value: canReflect.getName(source) + "."+canReflect.getName(this), + value: canReflect.getName(source) + "."+canReflect.getName(this) }); return fn; -} +}; //!steal-remove-end var isAt = function(index, reads) { From ea08077e74a205aed90a6a17f9721799eb59eb68 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Fri, 27 Oct 2017 17:20:00 -0500 Subject: [PATCH 21/36] 1.0.0-pre.9 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0a498d9..419730a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.8", + "version": "1.0.0-pre.9", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From abb5c73ce2fa3e3106667023251ec72fcdf4605d Mon Sep 17 00:00:00 2001 From: Chasen Le Hara Date: Fri, 10 Nov 2017 14:02:32 -0800 Subject: [PATCH 22/36] 1.0.0-pre.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 419730a..3c36283 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.9", + "version": "1.0.0-pre.10", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From c6becd0ff7c1c53f8fe72f34fd22b2ddbbf6708e Mon Sep 17 00:00:00 2001 From: Chasen Le Hara Date: Tue, 21 Nov 2017 10:46:03 -0800 Subject: [PATCH 23/36] Use new legacy module path introduced in can-event-queue 0.9.0 --- can-stache-key-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can-stache-key-test.js b/can-stache-key-test.js index e31effa..50a30be 100644 --- a/can-stache-key-test.js +++ b/can-stache-key-test.js @@ -1,7 +1,7 @@ var observeReader = require("can-stache-key"); var QUnit = require('steal-qunit'); var Observation = require('can-observation'); -var eventQueue = require('can-event-queue'); +var eventQueue = require('can-event-queue/map/legacy/legacy'); var dev = require('can-util/js/dev/dev'); var SimpleObservable = require("can-simple-observable"); From 57ce01df6d19ab5dec1f4fa2490c92f33e41c254 Mon Sep 17 00:00:00 2001 From: Chasen Le Hara Date: Tue, 21 Nov 2017 10:50:09 -0800 Subject: [PATCH 24/36] 1.0.0-pre.11 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3f137bc..8c06afd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.10", + "version": "1.0.0-pre.11", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From 3fbf236c195fa69ed272dd55dc6e291c2ee85fbe Mon Sep 17 00:00:00 2001 From: Kevin Phillips Date: Tue, 21 Nov 2017 16:51:10 -0600 Subject: [PATCH 25/36] 1.0.0-pre.12 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8843b85..2d93afe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.11", + "version": "1.0.0-pre.12", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From 855bdd311036d6d1dac174767017a950e3b63908 Mon Sep 17 00:00:00 2001 From: Kevin Phillips Date: Wed, 22 Nov 2017 09:29:18 -0600 Subject: [PATCH 26/36] giving warnings for @, callMethodsOnObservables, and removing automatic function calling --- can-stache-key-test.js | 45 +++++++++++++++++++----------------------- can-stache-key.js | 26 +++++++++--------------- 2 files changed, 29 insertions(+), 42 deletions(-) diff --git a/can-stache-key-test.js b/can-stache-key-test.js index 4819905..346b7ef 100644 --- a/can-stache-key-test.js +++ b/can-stache-key-test.js @@ -108,19 +108,20 @@ test('able to read things like can-define', 3, function(){ }); test("foundObservable called with observable object (#7)", function(){ - var map = { + var map = new SimpleMap({ isSaving: function(){ Observation.add(this, "_saving"); }, addEventListener: function(){} - }; + }); // must use an observation to make sure things are listening. var c = new Observation(function(){ observeReader.read(map,observeReader.reads("isSaving"),{ foundObservable: function(obs){ QUnit.equal(obs, map); - } + }, + callMethodsOnObservables: true }); }); canReflect.onValue(c, function(){}); @@ -228,48 +229,42 @@ QUnit.test("set onto observable objects and values", function(){ QUnit.equal(simple.get(), 1); }); -testHelpers.dev.devOnlyTest("a warning is displayed when functions are called by read()", function() { - var teardown = testHelpers.dev.willWarn(/"func" is being called as a function/); +testHelpers.dev.devOnlyTest("functions are not called by read()", function() { var func = function() { - QUnit.ok(true, "method called"); + QUnit.ok(false, "method called"); }; var data = { func: func }; var reads = observeReader.reads("func"); - observeReader.read(data, reads, { - warnOnFunctionCall: "A Warning" - }); + observeReader.read(data, reads); - QUnit.equal(teardown(), 1, "warning displayed"); + QUnit.ok(true); }); -testHelpers.dev.devOnlyTest("a warning is displayed when methods on observables are called by read()", function() { - var teardown = testHelpers.dev.willWarn(/"func" is being called as a function/); +testHelpers.dev.devOnlyTest("a warning is displayed when using @", function() { + var teardown = testHelpers.dev.willWarn("functions are no longer called by default so @ is unnecessary in '@func'."); var func = function() { - QUnit.ok(true, "method called"); + QUnit.ok(false, "method called"); }; - var data = new SimpleMap({ func: func }); - var reads = observeReader.reads("func"); + var data = { func: func }; + var reads = observeReader.reads("@func"); - observeReader.read(data, reads, { - callMethodsOnObservables: true - }); + observeReader.read(data, reads); QUnit.equal(teardown(), 1, "warning displayed"); }); -testHelpers.dev.devOnlyTest("a warning is not displayed when functions are read but not called", function() { - var teardown = testHelpers.dev.willWarn(/"func" is being called as a function/); +testHelpers.dev.devOnlyTest("a warning is given for `callMethodsOnObservables: true`", function() { + var teardown = testHelpers.dev.willWarn("can-stache-key: read() called with `callMethodsOnObservables: true`."); var func = function() { - QUnit.ok(false, "method called"); + QUnit.ok(true, "method called"); }; var data = new SimpleMap({ func: func }); - var reads = observeReader.reads("@func"); + var reads = observeReader.reads("func"); observeReader.read(data, reads, { - callMethodsOnObservables: true, - warnOnFunctionCall: "A Warning" + callMethodsOnObservables: true }); - QUnit.equal(teardown(), 0, "warning not displayed"); + QUnit.ok(teardown(), 1, "warning displayed"); }); diff --git a/can-stache-key.js b/can-stache-key.js index 0df51ed..4e33e56 100644 --- a/can-stache-key.js +++ b/can-stache-key.js @@ -62,8 +62,6 @@ observeReader = { // there are things that you need to evaluate when you get them back as a property read // for example a compute or a function you might need to call to get the next value to // actually check - // - isArgument - should be renamed to something like "onLastPropertyReadReturnFunctionInsteadOfCallingIt". - // This is used to make a compute out of that function if necessary. // - readCompute - can be set to `false` to prevent reading an ending compute. This is used by component to get a // compute as a delegate. In 3.0, this should be removed and force people to write "{@prop} change" // - callMethodsOnObservables - this is an overwrite ... so normal methods won't be called, but observable ones will. @@ -159,27 +157,21 @@ observeReader = { }, read: function(value, i, reads, options, state, prev){ if( isAt(i, reads) ) { - return i === reads.length ? bindName.call(value, prev) : value; + dev.warn( + (options.filename ? options.filename + ':' : '') + + (options.lineNumber ? options.lineNumber + ': ' : '') + + "functions are no longer called by default so @ is unnecessary in '" + + "@" + reads[0].key + "'." + ); } - //!steal-remove-start - dev.warn( - (options.filename ? options.filename + ':' : '') + - (options.lineNumber ? options.lineNumber + ': ' : '') + - '"' + reads[0].key + '" is being called as a function.\n' + - '\tThis will not happen automatically in an upcoming release.\n' + - '\tYou should call it explicitly using "' + reads[0].key + '()".\n\n' - ); - //!steal-remove-end - if(options.callMethodsOnObservables && canReflect.isObservableLike(prev) && canReflect.isMapLike(prev)) { + dev.warn("can-stache-key: read() called with `callMethodsOnObservables: true`."); + return value.apply(prev, options.args || []); } - else if ( options.isArgument && i === reads.length ) { - return options.proxyMethods !== false ? bindName.call(value, prev) : value; - } - return value.apply(prev, options.args || []); + return options.proxyMethods !== false ? bindName.call(value, prev) : value; } }, { From 7a27d14170d5d5768e11a0064c04348e3bec5c71 Mon Sep 17 00:00:00 2001 From: Kevin Phillips Date: Wed, 22 Nov 2017 09:29:35 -0600 Subject: [PATCH 27/36] 1.0.0-pre.13 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2d93afe..c7715e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.12", + "version": "1.0.0-pre.13", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From 8bd8c5c0f2829fa0cc4b6c5af516498cc05edb2f Mon Sep 17 00:00:00 2001 From: Kevin Phillips Date: Tue, 28 Nov 2017 10:52:44 -0600 Subject: [PATCH 28/36] removing incorrect warning for @ --- can-stache-key-test.js | 13 ------------- can-stache-key.js | 9 --------- 2 files changed, 22 deletions(-) diff --git a/can-stache-key-test.js b/can-stache-key-test.js index 346b7ef..4be971c 100644 --- a/can-stache-key-test.js +++ b/can-stache-key-test.js @@ -241,19 +241,6 @@ testHelpers.dev.devOnlyTest("functions are not called by read()", function() { QUnit.ok(true); }); -testHelpers.dev.devOnlyTest("a warning is displayed when using @", function() { - var teardown = testHelpers.dev.willWarn("functions are no longer called by default so @ is unnecessary in '@func'."); - var func = function() { - QUnit.ok(false, "method called"); - }; - var data = { func: func }; - var reads = observeReader.reads("@func"); - - observeReader.read(data, reads); - - QUnit.equal(teardown(), 1, "warning displayed"); -}); - testHelpers.dev.devOnlyTest("a warning is given for `callMethodsOnObservables: true`", function() { var teardown = testHelpers.dev.willWarn("can-stache-key: read() called with `callMethodsOnObservables: true`."); var func = function() { diff --git a/can-stache-key.js b/can-stache-key.js index 4e33e56..7323683 100644 --- a/can-stache-key.js +++ b/can-stache-key.js @@ -156,15 +156,6 @@ observeReader = { return value && canReflect.isFunctionLike(value) && !canReflect.isConstructorLike(value); }, read: function(value, i, reads, options, state, prev){ - if( isAt(i, reads) ) { - dev.warn( - (options.filename ? options.filename + ':' : '') + - (options.lineNumber ? options.lineNumber + ': ' : '') + - "functions are no longer called by default so @ is unnecessary in '" + - "@" + reads[0].key + "'." - ); - } - if(options.callMethodsOnObservables && canReflect.isObservableLike(prev) && canReflect.isMapLike(prev)) { dev.warn("can-stache-key: read() called with `callMethodsOnObservables: true`."); From ca84fd12f3743420161c5fd1b163a574e981828c Mon Sep 17 00:00:00 2001 From: Kevin Phillips Date: Tue, 28 Nov 2017 10:53:05 -0600 Subject: [PATCH 29/36] 1.0.0-pre.14 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c7715e3..7b2ccf9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.13", + "version": "1.0.0-pre.14", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From 05581218107e13514b688f0658774e4b54027906 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Fri, 1 Dec 2017 14:14:36 -0600 Subject: [PATCH 30/36] use OR directly --- can-stache-key-test.js | 5 +++-- can-stache-key.js | 10 +++++----- package.json | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/can-stache-key-test.js b/can-stache-key-test.js index 4be971c..073ef26 100644 --- a/can-stache-key-test.js +++ b/can-stache-key-test.js @@ -4,6 +4,7 @@ var Observation = require('can-observation'); var eventQueue = require('can-event-queue/map/legacy/legacy'); var SimpleObservable = require("can-simple-observable"); var testHelpers = require('can-test-helpers'); +var ObservationRecorder = require("can-observation-recorder"); var SimpleMap = require("can-simple-map"); var canReflect = require("can-reflect"); @@ -82,7 +83,7 @@ test('able to read things like can-define', 3, function(){ var prop = "PROP"; Object.defineProperty(obj, "prop",{ get: function(){ - Observation.add(obj,"prop"); + ObservationRecorder.add(obj,"prop"); return prop; }, set: function(val){ @@ -110,7 +111,7 @@ test('able to read things like can-define', 3, function(){ test("foundObservable called with observable object (#7)", function(){ var map = new SimpleMap({ isSaving: function(){ - Observation.add(this, "_saving"); + ObservationRecorder.add(this, "_saving"); }, addEventListener: function(){} }); diff --git a/can-stache-key.js b/can-stache-key.js index 7323683..c46b216 100644 --- a/can-stache-key.js +++ b/can-stache-key.js @@ -1,4 +1,4 @@ -var Observation = require('can-observation'); +var ObservationRecorder = require('can-observation-recorder'); var dev = require('can-log/dev/dev'); var each = require('can-util/js/each/each'); var canSymbol = require("can-symbol"); @@ -10,7 +10,7 @@ var getValueSymbol = canSymbol.for("can.getValue"); var setValueSymbol = canSymbol.for("can.setValue"); var isValueLikeSymbol = canSymbol.for("can.isValueLike"); -var peek = Observation.ignore(canReflect.getKeyValue.bind(canReflect)); +var peek = ObservationRecorder.ignore(canReflect.getKeyValue.bind(canReflect)); var observeReader; var bindName = Function.prototype.bind; @@ -50,8 +50,8 @@ var specialRead = {index: true, key: true, event: true, element: true, viewModel var checkForObservableAndNotify = function(options, state, getObserves, value, index){ if(options.foundObservable && !state.foundObservable) { - if(Observation.trapsCount()) { - Observation.addAll( getObserves() ); + if(ObservationRecorder.trapsCount()) { + ObservationRecorder.addMany( getObserves() ); options.foundObservable(value, index); state.foundObservable = true; } @@ -79,7 +79,7 @@ observeReader = { }; var getObserves; if(options.foundObservable) { - getObserves = Observation.trap(); + getObserves = ObservationRecorder.trap(); } // `cur` is the current value. diff --git a/package.json b/package.json index 7b2ccf9..6362ec3 100644 --- a/package.json +++ b/package.json @@ -46,13 +46,14 @@ "dependencies": { "can-log": "^0.1.2", "can-namespace": "1.0.0", - "can-observation": "^4.0.0-pre.2", + "can-observation-recorder": "<2.0.0", "can-reflect": "^1.1.0", "can-reflect-promise": "^2.0.0-pre.2", "can-symbol": "^1.0.0", "can-util": "^3.9.0" }, "devDependencies": { + "can-observation": "^4.0.0-pre.2", "can-event-queue": "<2.0.0", "can-simple-map": "^4.0.0-pre.0", "can-simple-observable": "^2.0.0-pre.11", From c766eb1d41da046ff9969e704279c5a01203bb75 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Fri, 1 Dec 2017 14:14:44 -0600 Subject: [PATCH 31/36] 1.0.0-pre.15 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6362ec3..a4f99d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.14", + "version": "1.0.0-pre.15", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From a484584861257ca8ab754e79e1be8f067e3f6e25 Mon Sep 17 00:00:00 2001 From: Chasen Le Hara Date: Tue, 2 Jan 2018 15:35:35 -0800 Subject: [PATCH 32/36] Use can-event-queue/map/map instead of can-event-queue/map/legacy/legacy --- can-stache-key-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can-stache-key-test.js b/can-stache-key-test.js index 073ef26..77834cd 100644 --- a/can-stache-key-test.js +++ b/can-stache-key-test.js @@ -1,7 +1,7 @@ var observeReader = require("can-stache-key"); var QUnit = require('steal-qunit'); var Observation = require('can-observation'); -var eventQueue = require('can-event-queue/map/legacy/legacy'); +var eventQueue = require('can-event-queue/map/map'); var SimpleObservable = require("can-simple-observable"); var testHelpers = require('can-test-helpers'); var ObservationRecorder = require("can-observation-recorder"); From c72856204bede66fce729c43d6d59dc7ce766f1b Mon Sep 17 00:00:00 2001 From: Chasen Le Hara Date: Tue, 2 Jan 2018 15:37:30 -0800 Subject: [PATCH 33/36] 1.0.0-pre.16 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a4f99d9..6dc7868 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.15", + "version": "1.0.0-pre.16", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From 3e50ff835a4c42f1fd49910b09afd4c7f3202133 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Tue, 9 Jan 2018 14:34:16 -0500 Subject: [PATCH 34/36] Fix QUnit.ok usages --- can-stache-key-test.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/can-stache-key-test.js b/can-stache-key-test.js index 77834cd..35fcef3 100644 --- a/can-stache-key-test.js +++ b/can-stache-key-test.js @@ -130,9 +130,12 @@ test("foundObservable called with observable object (#7)", function(){ test("can read from strings", function(){ var context = " hi there "; - var result = observeReader.read(context,observeReader.reads("trim"),{}); - QUnit.ok(result, context.trim); + QUnit.equal( + result.value(context), + context.trim(context), + 'trim method works' + ); }); test("read / write to DefineMap", function(){ @@ -254,5 +257,5 @@ testHelpers.dev.devOnlyTest("a warning is given for `callMethodsOnObservables: t callMethodsOnObservables: true }); - QUnit.ok(teardown(), 1, "warning displayed"); + QUnit.equal(teardown(), 1, "warning displayed"); }); From eb1357dba3141f0178563bd597913421938f460e Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Tue, 9 Jan 2018 14:43:36 -0500 Subject: [PATCH 35/36] 1.0.0-pre.17 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6dc7868..05ed40f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "can-stache-key", - "version": "1.0.0-pre.16", + "version": "1.0.0-pre.17", "description": "Read and write keys on a value", "homepage": "https://canjs.com", "repository": { From 077b7030fbc1d040f3c6488dc184dafad9f02238 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Fri, 26 Jan 2018 20:27:39 -0600 Subject: [PATCH 36/36] pointing at the right versions --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 05ed40f..b39a83e 100644 --- a/package.json +++ b/package.json @@ -44,18 +44,18 @@ ] }, "dependencies": { - "can-log": "^0.1.2", + "can-log": "^1.0.0", "can-namespace": "1.0.0", - "can-observation-recorder": "<2.0.0", + "can-observation-recorder": "^1.0.0", "can-reflect": "^1.1.0", - "can-reflect-promise": "^2.0.0-pre.2", + "can-reflect-promise": "^2.0.0", "can-symbol": "^1.0.0", "can-util": "^3.9.0" }, "devDependencies": { "can-observation": "^4.0.0-pre.2", "can-event-queue": "<2.0.0", - "can-simple-map": "^4.0.0-pre.0", + "can-simple-map": "^4.0.0", "can-simple-observable": "^2.0.0-pre.11", "can-test-helpers": "^1.1.0", "detect-cyclic-packages": "^1.1.0",