Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
highlightedAutocompletionIndex$: (autocompletions$, valueChange$, hideAutocompletions$, selectedAutocompletionInput$) =>
Rx.Observable.combineLatest(
Rx.Observable.merge(
Rx.Observable.merge( // reset position on text and when autocompletions list hides
valueChange$,
hideAutocompletions$
)
.map(() => ({ direct: 0 }))
.delay(1), // reset after fetching value from autocompletions
selectedAutocompletionInput$
),
autocompletions$,
(positionModifier, autocompletions) => ({ positionModifier, autocompletions })
).scan(0, (position, { positionModifier, autocompletions }) => {
if(positionModifier.hasOwnProperty('modifier')) {
position = position + positionModifier.modifier;
} else if(positionModifier.hasOwnProperty('direct')) {
position = positionModifier.direct;
autocompletions$: (textFieldValue$, datalistAttr$) =>
Rx.Observable.combineLatest(
textFieldValue$,
datalistAttr$,
(value, datalist) =>
value.length ?
datalist // choose keywords matching to value and sort them by ranking
.map((keywords) => ({
value: keywords[0], // show only the first keyword
// but match all of them and choose one with the highest ranking
score: Math.max.apply(Math, keywords.map(function(keyword, index) {
var index = keyword.toLowerCase().indexOf(value.toLowerCase());
if(index === -1) {
return -Infinity;
}
return (100 - index * Math.abs(keyword.length - value.length));
// IMPORTS =========================================================================================
require("../../common/scripts/polyfills");
let {Rx, h, createStream, render} = require("cyclejs");
// DATA-SOURCE =====================================================================================
let input$ = Rx.Observable.fromPromise(
new Promise((resolve, reject) => {
resolve("CycleJS");
})
);
// INTERACTION =====================================================================================
let interaction$ = createStream(vtree$ => {
return render(vtree$, "main").interaction$;
});
// [INTERACTION] <- INTENT =========================================================================
let changeName$ = createStream(interaction$ => {
return interaction$.choose("[name=name]", "input").map(event => event.target.value);
});
// [INTENT] <- MODEL ===============================================================================
function toVTStream(diagramData, scheduler) {
let singleMarbleStreams = diagramData.get('notifications').map(item =>
justIncomplete(item, scheduler).delay(item.get('time'), scheduler)
).toArray();
// Necessary correction to include marbles at time exactly diagramData.end:
let correctedEndTime = diagramData.get('end') + 0.01;
return Rx.Observable.merge(singleMarbleStreams)
.takeUntilWithTime(correctedEndTime, scheduler)
.publish().refCount();
}
Object.keys(definitionObj).forEach((name) => {
let [ selector, event ] = name.split('@');
if(!eventsMap.hasOwnProperty(selector)) {
eventsMap[selector] = { };
}
if(definitionObj[name] instanceof Rx.Observable) {
eventsMap[selector][event] = definitionObj[name];
} else {
eventsMap[selector][event] = createObservable(
scheduler,
Rx.ReactiveTest.onNext(20, definitionObj[name])
);
}
});
let fnArgs = getParametersNames(fn).map((name) => {
if(!(providedArgs[name] instanceof Rx.Observable)) {
return createObservable();
} else {
return providedArgs[name];
}
});
injectTestingUtils((mockInteractions) => {
let mock = mockInteractions();
assert.instanceOf(mock.choose(), Rx.Observable);
assert.instanceOf(mock.choose('button', 'click'), Rx.Observable);
assert.instanceOf(mock.choose('#field', 'input'), Rx.Observable);
assert.instanceOf(mock.choose('abc', 'xyz'), Rx.Observable);
}));
injectTestingUtils((mockInteractions) => {
let mock = mockInteractions();
assert.instanceOf(mock.choose(), Rx.Observable);
assert.instanceOf(mock.choose('button', 'click'), Rx.Observable);
assert.instanceOf(mock.choose('#field', 'input'), Rx.Observable);
assert.instanceOf(mock.choose('abc', 'xyz'), Rx.Observable);
}));
fnArgs.forEach((name) => {
if(!(args[name] instanceof Rx.Observable)) {
args[name] = createObservable();
}
});
selectedAutocompletionChange$: (mousedownOnAutocompletion$, enter$) =>
Rx.Observable.merge(
enter$,
mousedownOnAutocompletion$
).map(() => true),
showAutocompletions$: (focusOnField$, notEnter$) =>