From e1a50890e9a8c630a162bc49535459d53721de17 Mon Sep 17 00:00:00 2001 From: Barney Carroll Date: Tue, 15 May 2018 23:01:30 +0100 Subject: [PATCH] stream: Removed `valueOf` & `toString` methods (fixes #2150) (#2151) * stream: Removed `valueOf` & `toString` methods (fixes #2150) * Update stream documentation --- docs/change-log.md | 1 + docs/stream.md | 7 ------- stream/change-log.md | 7 +++++++ stream/stream.js | 3 +-- stream/tests/test-stream.js | 25 ------------------------- 5 files changed, 9 insertions(+), 34 deletions(-) create mode 100644 stream/change-log.md diff --git a/docs/change-log.md b/docs/change-log.md index bfaa54a3..dee3406b 100644 --- a/docs/change-log.md +++ b/docs/change-log.md @@ -55,6 +55,7 @@ ### v1.1.7 +- Stream references no longer magically coerce to their underlying values ([#2150](https://github.com/MithrilJS/mithril.js/pull/2150), breaking change: `mithril-stream@2.0.0`) - Promise polyfill implementation separated from polyfilling logic. - `PromisePolyfill` is now available on the exported/global `m`. diff --git a/docs/stream.md b/docs/stream.md index 2ad04c20..679294be 100644 --- a/docs/stream.md +++ b/docs/stream.md @@ -504,13 +504,6 @@ var serialized = JSON.stringify(value) console.log(serialized) // logs 123 ``` -Streams also implement a `valueOf` method that returns the value of the stream. - -```javascript -var value = stream(123) -console.log("test " + value) // logs "test 123" -``` - --- ### Streams do not trigger rendering diff --git a/stream/change-log.md b/stream/change-log.md new file mode 100644 index 00000000..45ccd0da --- /dev/null +++ b/stream/change-log.md @@ -0,0 +1,7 @@ +# Change log for stream + +## 2.0.0 +- stream: Removed `valueOf` & `toString` methods ([#2150](https://github.com/MithrilJS/mithril.js/pull/2150) + +## 1.1.0 +- stream: Move the "use strict" directive inside the IIFE [#1831](https://github.com/MithrilJS/mithril.js/issues/1831) ([#1893](https://github.com/MithrilJS/mithril.js/pull/1893)) diff --git a/stream/stream.js b/stream/stream.js index e9438480..20fd6378 100644 --- a/stream/stream.js +++ b/stream/stream.js @@ -19,7 +19,7 @@ function initStream(stream) { stream.constructor = createStream stream._state = {id: guid++, value: undefined, state: 0, derive: undefined, recover: undefined, deps: {}, parents: [], endStream: undefined, unregister: undefined} stream.map = stream["fantasy-land/map"] = map, stream["fantasy-land/ap"] = ap, stream["fantasy-land/of"] = createStream - stream.valueOf = valueOf, stream.toJSON = toJSON, stream.toString = valueOf + stream.toJSON = toJSON Object.defineProperties(stream, { end: {get: function() { @@ -101,7 +101,6 @@ function unregisterStream(stream) { function map(fn) {return combine(function(stream) {return fn(stream())}, [this])} function ap(stream) {return combine(function(s1, s2) {return s1()(s2())}, [stream, this])} -function valueOf() {return this._state.value} function toJSON() {return this._state.value != null && typeof this._state.value.toJSON === "function" ? this._state.value.toJSON() : this._state.value} function valid(stream) {return stream._state } diff --git a/stream/tests/test-stream.js b/stream/tests/test-stream.js index 09b01209..7ea944d7 100644 --- a/stream/tests/test-stream.js +++ b/stream/tests/test-stream.js @@ -276,31 +276,6 @@ o.spec("stream", function() { o(spy.callCount).equals(1) }) }) - o.spec("valueOf", function() { - o("works", function() { - o(Stream(1).valueOf()).equals(1) - o(Stream("a").valueOf()).equals("a") - o(Stream(true).valueOf()).equals(true) - o(Stream(null).valueOf()).equals(null) - o(Stream(undefined).valueOf()).equals(undefined) - o(Stream({a: 1}).valueOf()).deepEquals({a: 1}) - o(Stream([1, 2, 3]).valueOf()).deepEquals([1, 2, 3]) - o(Stream().valueOf()).equals(undefined) - }) - o("allows implicit value access in mathematical operations", function() { - o(Stream(1) + Stream(1)).equals(2) - }) - }) - o.spec("toString", function() { - o("aliases valueOf", function() { - var stream = Stream(1) - - o(stream.toString).equals(stream.valueOf) - }) - o("allows implicit value access in string operations", function() { - o(Stream("a") + Stream("b")).equals("ab") - }) - }) o.spec("toJSON", function() { o("works", function() { o(Stream(1).toJSON()).equals(1)