Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test("SongModel.fetch fetches songs correctly", withMock(function(t) {
var p_songs = SongModel.fetch("url", SONG_DURATION / 10)
.takeUntil(Bacon.later((songs.length + 1) * SONG_DURATION))
.last();
p_songs.onValue(function(ss) {
t.deepEqual(ss.reverse(), _.map(songs, function(song) {
return _.extend({}, song, {
favorite: SongModel.isFavorite(song)
});
}));
t.end();
});
}));
testRender(<div> {}}
style={{display: "block",
color: Bacon.constant("red"),
background: "green"}}>
<p>{Bacon.constant(["Hello"])}</p>
<p>{Bacon.constant(["World"])}</p>
</div>,
'<div style="display:block;color:red;background:green"><p>Hello</p><p>World</p></div>')
testRender(<a style="{Bacon.constant({color:" href="#lol">
{Bacon.constant("Hello")} {Bacon.constant("world!")}
</a>,
'<a style="color:red" href="#lol">Hello world!</a>')
testRender(<div>{Bacon.later(1000,0)}</div>, "")
testRender(<div>{Bacon.later(1000,0).toProperty(1)}</div>, "<div>1</div>")
testRender(<div>{Bacon.later(1000,0)} {Bacon.constant(0)}</div>, "")
const Custom = ({prop, ...props}) => <div>{`${prop} ${JSON.stringify(props)}`}</div>
testRender(,
'<div>Bacon.constant(not-lifted) {}</div>')
testRender(,
'<div>lifted {}</div>')
testRender(,
'<div>lifted anyway {}</div>')
const Spread = props => <div>
</div>
createNObservable('Bacon', 700, function(){
return Bacon.later(0, 1);
})
.flatMapLatest(() => {
if (remainingRetryCount === 0) {
return new Bacon.Error(`WebSocket connection failed ${MAX_RETRY_COUNT} times!`);
}
const retryCount = (MAX_RETRY_COUNT - remainingRetryCount + 1);
Logger.warn(`WebSocket connection closed, reconnecting... (${retryCount}/${MAX_RETRY_COUNT})`);
return Bacon.later(RETRY_DELAY, null).flatMapLatest(() => {
return openWsStream({ url, authMessage, startPing, stopPing }, remainingRetryCount - 1);
});
});
function asStream (fn) {
return Bacon.later(0).flatMapLatest(Bacon.try(fn));
}
shortcuts.flatMapLatest(function(shortcut) {
return Bacon.once(shortcut).merge(Bacon.later(2000, "(nothing)"))
}).onValue(function(text) {
document.querySelector("#shortcut").textContent = text
Bacon.repeat(() => Bacon.later(interval, true).flatMap(f))
)
function fetchUrl(url, bodyIsBinary) {
if (responseCache[url]) {
return Bacon.later(0, responseCache[url])
}
return Bacon.fromNodeCallback((callback) => {
request(url, { timeout: 20000, encoding: bodyIsBinary ? null : undefined }, (error, response, body) => {
if (!error && response.statusCode == 200) {
if (!url.endsWith('.tgz')) {
responseCache[url] = body
}
callback(null, body)
} else {
const statusCode = response ? response.statusCode : 'n/a'
callback(`Failed to fetch ${url} because of error '${error}' and/or HTTP status ${statusCode}`)
}
})
})
}