Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const newItemsStream = msgStream.filter(R.propEq('type', 'add')).map(R.prop('item'))
const removedItemsStream = msgStream.filter(R.propEq('type', 'rm')).map(R.prop('path'))
const itemsProp = Bacon.update(
[],
[newItemsStream], (items, item) => items.concat({
title: Path.basename(item.path),
content: fs.readFileSync(item.path, 'utf8')
}),
[removedItemsStream], (items, path) => items.filter(item => item.path !== path)
)
const sifterProp = itemsProp
.debounce(50) // avoid creating a new sifter too often
.map(items => new Sifter(items))
Bacon.combineWith(sifterProp, queryStream, (sifter, q) =>
sifter.search(q, {
fields: ['title', 'content'],
sort: [{field: 'title', direction: 'asc'}]
})
)
.onValue(r => emit('results', r))
disposeStream.onValue(terminate)
}
// TODO can remove?
project.searchBus.plug(reactPanel.searchProp.toEventStream())
this._disposables = new DisposableValues()
this._disposables.add(
sideEffects.persistSortField(reactPanel.sortFieldProp, atom.config),
sideEffects.persistSortDirection(reactPanel.sortDirectionProp, atom.config),
sideEffects.persistPanelHeight(reactPanel.panelHeightProp, atom.config),
sideEffects.toggleAtomWindowAndPanel(toggleAtomWinCmdStream, this._atomPanel, atom),
sideEffects.showPanel(focusCmdStream, this._atomPanel),
sideEffects.togglePanel(togglePanelCmdStream, this._atomPanel),
sideEffects.updatePreview(selectedFileProp, atom.workspace)
)
const enterKeyStream = keyDownBus.filter(R.propEq('keyCode', 13))
const filePathStream = Bacon
.combineWith(selectedFileProp, project.newFilePathProp, (f, newFilePath) => {
return f ? f.path : newFilePath
})
this._disposables.add(
sideEffects.openEditor(filePathStream, enterKeyStream, atom.workspace)
)
}
const i = items.findIndex(({id}) => files[id].path === currentPath)
return {
item: items[i],
path: current.path,
index: i
}
} else {
return current // stay with current
}
}
)
.skipDuplicates()
return {
selectedIndexStream: selectedProp.changes().map('.index'),
selectedFileProp: Bacon
.combineWith(selectedProp, filesProp, (selected, files) => {
const id = R.path(['item', 'id'], selected)
return files[id]
})
}
}
function model(initialHeight, initialWeight) {
const setHeight = createAction()
const setWeight = createAction()
const height = setHeight.$.toProperty(initialHeight)
const weight = setWeight.$.toProperty(initialWeight)
const bmi = Bacon.combineWith(weight, height, (w, h) => (
Math.round(w / (h * h * 0.0001))
))
// yeah. model is just a pure factory function that returns plain object
return { setHeight, setWeight, height, weight, bmi }
}
export function getBroadcastedSong(p_route, p_radios) {
const p_radio = getCurrentRadio(p_route);
const p_song = Bacon.combineWith(p_radio, p_radios, (radio, radios) => {
return radios[radio].nowPlaying;
});
return p_song.skipDuplicates(_.isEqual);
}
.add('bacon', function (deferred) {
var source = bacon.fromArray(a);
var inc = source.filter(isPositive).map(returnPlus1);
var dec = source.filter(isNegative).map(returnMinus1);
var count = inc.merge(dec).scan(0, addXY);
var label = bacon.fromArray(['initial', 'Count is ']);
var view = bacon.combineWith(renderWithArgs, label, count);
runners.runBacon(deferred, view);
}, options)
.add('bacon', function (deferred) {
var source = bacon.fromArray(a);
var inc = source.filter(isPositive).map(returnPlus1);
var dec = source.filter(isNegative).map(returnMinus1);
var count = inc.merge(dec).scan(0, addXY);
var label = bacon.fromArray(['initial', 'Count is ']);
var view = bacon.combineWith(renderWithArgs, label, count);
runners.runBacon(deferred, view);
}, options)
export function getSongBeingPlayed(p_radios, p_playBus) {
const p_cmds = p_playBus.filter(cmd => cmd.type != "stop");
const p_song = Bacon.combineWith(p_radios, p_cmds, function(radios, cmd) {
switch (cmd.type) {
case "loading":
case "spotify":
return cmd;
case "radio":
return radios[cmd.radio].nowPlaying;
default:
return new Bacon.Error();
}
});
return p_song.skipDuplicates(_.isEqual);
}
export function getRadioState(SongController, p_favSongs, p_radioSongs) {
const p_songs = Bacon.combineWith(
SongController.mergeFavsAndSongs,
p_radioSongs,
p_favSongs
);
const p_pastSongs = p_songs.map(_.tail);
const p_nowPlaying = p_songs
.map(songs => (_.isEmpty(songs) ? { type: "loading" } : _.head(songs)))
.flatMapError(data => {
const code = data && data.error && data.error.code;
return Bacon.once(
code === 100
? {
type: "unknown"