stream: Removed valueOf & toString methods (fixes #2150) (#2151)

* stream: Removed `valueOf` & `toString` methods (fixes #2150)

* Update stream documentation
This commit is contained in:
Barney Carroll 2018-05-15 23:01:30 +01:00 committed by Pierre-Yves Gérardy
parent 4823369abe
commit e1a50890e9
5 changed files with 9 additions and 34 deletions

View file

@ -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`.

View file

@ -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

7
stream/change-log.md Normal file
View file

@ -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))

View file

@ -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 }

View file

@ -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)