Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.fromNodeCallback(fileReader.read.bind(fileReader), notesPath.fullPath(filename), fileStats)
.map(value => {
readResult.value = value === undefined ? null : value // make sure value cannot be undefined
return readResult
})
.mapError(err => {
console.warn('failed to read file:', err)
return readResult
})
})
})
}
const newFileS = createFileStream('add')
const fileReaderResultS = Bacon
.mergeAll(
createFileReaderResultsStream(newFileS, notesCache),
createFileReaderResultsStream(createFileStream('change'))
)
const updateNoteProps = (note: Object, fields: Array, filename: string) => {
note.id = process.hrtime().toString()
fields.forEach(field => {
if (field.value) {
note[field.notePropName] = field.value(note, filename)
}
})
}
const sifterP = Bacon
.update(
_saveRowHeightOnWinResize (rowsS: Bacon.Stream) {
return Bacon
.mergeAll(
rowsS.take(1),
Bacon.fromEvent(window, 'resize'))
.debounceImmediate(50) // ms
.onValue(() => {
const td = this._queryDOM('td')
if (td && td.clientHeight > 0) {
atom.config.set('textual-velocity.rowHeight', td.clientHeight)
}
})
}
})
this.listHeightP = Bacon
.update(0,
[viewCtrl.listHeightS], R.nthArg(-1),
[viewCtrl.sessionStartS.map('.listHeight')], R.nthArg(-1))
.skipDuplicates()
this.rowHeightP = Bacon
.update(0,
[viewCtrl.rowHeightS], R.nthArg(-1),
[viewCtrl.sessionStartS.map('.rowHeight')], R.nthArg(-1))
.skipDuplicates()
const itemsP = this.sifterResultP.map('.items')
const lastSelectionChangeTimeP = Bacon
.mergeAll(
viewCtrl.keyUpS.map(Date.now),
viewCtrl.keyDownS.map(Date.now),
viewCtrl.clickedCellS.map(Date.now),
this.searchStrS.map(Date.now),
)
.toProperty(Date.now())
this.selectedFilenameS = Bacon
.update(undefined,
[viewCtrl.activePathS, this.notesPathP, this.notesP, lastSelectionChangeTimeP], (old, path, notesPath, notes, lastSelectionChangeTime) => {
if (Date.now() - lastSelectionChangeTime < 100) return old // make sure selection by user (e.g. keyup) has precedence over path change, since the delay of the trigger otherwise cause jumpy behavior
if (!path) return
const filename = notesPath.filename(path)
if (notes[filename]) return filename
},
createNObservable('Bacon', 500, function(){
return Bacon.mergeAll(baseBacon(), baseBacon(), baseBacon(), baseBacon());
})
switch (path) {
case "/a":
routes.a.push();
break;
case "/b":
routes.b.push();
break;
default:
routes.errors.push();
break;
}
}
}
};
const p_route = Bacon.mergeAll([
routes.a.map("a"),
routes.b.map("b"),
routes.errors.map("errors")
]);
p_route
.fold([], (acc, elem) => acc.concat([elem]))
.subscribe(function(ev) {
expect(ev.hasValue()).toBeTruthy();
expect(ev.value()).toStrictEqual(["a", "b", "errors"]);
done();
return Bacon.noMore;
});
_renderResultsOnDataChanges (presenter: PresenterType, view: ViewType) {
return Bacon
.combineTemplate({
columns: presenter.columnHeadersP,
forcedScrollTop: presenter.forcedScrollTopP,
itemsCount: presenter.itemsCountP,
listHeight: presenter.listHeightP,
loadingProgress: presenter.loadingProgressP,
paginationStart: presenter.paginationP.map('.start'),
rowHeight: presenter.rowHeightP,
rows: presenter.rowsS,
searchStr: presenter.searchStrP,
sort: presenter.sortP
})
.sampledBy(
Bacon.mergeAll(
presenter.listHeightP.changes(),
presenter.forcedScrollTopP.changes(),
presenter.rowsS))
.onValue((params: ResultsViewParamsType) => {
view.renderResults(params)
})
}
.add('bacon', function(deferred) {
var streams = a.map(bacon.fromArray);
runners.runBacon(deferred, bacon.mergeAll(streams).reduce(0, sum));
}, options)
.add('lodash', function() {
this.keyEscS = newKeyS(27)
this.keyUpS = newKeyS(38)
this.listHeightS = Bacon
.mergeAll(
this._listHeightBus,
atoms.createConfigStream('textual-velocity.listHeight'))
.skipDuplicates()
this.sortDirectionS = Bacon
.mergeAll(
this._sortDirectionBus,
atoms.createConfigStream('textual-velocity.sortDirection'))
.skipDuplicates()
this.sortFieldS = Bacon
.mergeAll(
this._sortFieldBus,
atoms.createConfigStream('textual-velocity.sortField'))
.skipDuplicates()
}
function repeat(
interval: number,
f: () => Bacon.Property
): Bacon.Property {
return ignoreNonRecurringErrors(
6 * interval,
5,
Bacon.mergeAll(
f().toEventStream(),
Bacon.repeat(() => Bacon.later(interval, true).flatMap(f))
)
).toProperty();
}
export function ignoreNonRecurringErrors(
interval: number,
threshold: number,
stream: Bacon.EventStream
): Bacon.EventStream {
return Bacon.mergeAll(
stream.skipErrors() as Bacon.EventStream,
stream
.errors()
.mapError(e => e)
.bufferWithTime(interval)
.filter(errors => errors.length >= threshold)
.flatMap(
errors => new Bacon.Error(errors[errors.length - 1])
) as Bacon.EventStream
);
}