Fix the Stream.HALT warning's condition

Previously, it warned on all *but* the first use, which is obviously
wrong. This corrects it to correctly fire on only the first use.
This commit is contained in:
Isiah Meadows 2019-02-05 11:03:50 -05:00
parent b91a10a233
commit 2a9b3964ca
2 changed files with 17 additions and 22 deletions

View file

@ -13,7 +13,7 @@ Stream["fantasy-land/of"] = Stream
var warnedHalt = false var warnedHalt = false
Object.defineProperty(Stream, "HALT", { Object.defineProperty(Stream, "HALT", {
get: function() { get: function() {
warnedHalt && console.log("HALT is deprecated and has been renamed to SKIP"); warnedHalt || console.log("HALT is deprecated and has been renamed to SKIP");
warnedHalt = true warnedHalt = true
return Stream.SKIP return Stream.SKIP
} }

View file

@ -42,30 +42,25 @@ o.spec("stream", function() {
o(b()).equals(2) o(b()).equals(2)
}) })
o("can HALT", function() { // NOTE: this *must* be the *only* uses of `Stream.HALT` in the entire
var a = Stream(2) // test suite.
var b = a.map(function(value) { o("HALT is a deprecated alias of SKIP and warns once", function() {
return value === 5
? Stream.HALT
: value
})
a(5)
o(b()).equals(2)
})
o("warns HALT deprecated", function() {
var log = console.log var log = console.log
var warning = "" var warnings = []
console.log = function(a) { console.log = function(a) {
warning = a warnings.push(a)
} }
Stream.HALT try {
o(Stream.HALT).equals(Stream.SKIP)
console.log = log o(warnings).deepEquals(["HALT is deprecated and has been renamed to SKIP"])
o(Stream.HALT).equals(Stream.SKIP)
o(warning).equals("HALT is deprecated and has been renamed to SKIP") o(warnings).deepEquals(["HALT is deprecated and has been renamed to SKIP"])
o(Stream.HALT).equals(Stream.SKIP)
o(warnings).deepEquals(["HALT is deprecated and has been renamed to SKIP"])
} finally {
console.log = log
}
}) })
}) })
o.spec("combine", function() { o.spec("combine", function() {
@ -364,7 +359,7 @@ o.spec("stream", function() {
var count = 0 var count = 0
var a = Stream(1) var a = Stream(1)
var b = Stream.lift(function() { var b = Stream.lift(function() {
return Stream.HALT return Stream.SKIP
}, a)["fantasy-land/map"](function() { }, a)["fantasy-land/map"](function() {
count++ count++
return 1 return 1