Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function edit(dom: DomSource) {
const label = query(`.${TodoItemStyles.labelClass}`, dom)
const input = query(`.${TodoItemStyles.editClass}`, dom)
const blur$ = events('blur', input)
const dblClick$ = events('dblclick', label)
const keyDown$ = events('keydown', input)
const enterKey$ =
tap((event) => event.preventDefault(), filter(isEnterKey, keyDown$))
const editing$ =
hold(startWith(false, merge(
constant(false, enterKey$),
constant(true, dblClick$),
constant(false, blur$),
)))
const value$ =
map(trimmedValue, filter(isItemFilled, merge(enterKey$, blur$)))
return { editing$, value$ }
}
export function edit(dom: DomSource) {
const label = query(`.${TodoItemStyles.labelClass}`, dom)
const input = query(`.${TodoItemStyles.editClass}`, dom)
const blur$ = events('blur', input)
const dblClick$ = events('dblclick', label)
const keyDown$ = events('keydown', input)
const enterKey$ =
tap((event) => event.preventDefault(), filter(isEnterKey, keyDown$))
const editing$ =
hold(startWith(false, merge(
constant(false, enterKey$),
constant(true, dblClick$),
constant(false, blur$),
)))
const value$ =
map(trimmedValue, filter(isItemFilled, merge(enterKey$, blur$)))
return { editing$, value$ }
}
export function FilterTodos(sinks: Sinks): Sources {
const { showActiveTodos$, showAllTodos$, showCompletedTodos$, todos$ } = sinks
const history$ =
merge(
constant('/', showAllTodos$),
constant('/active', showActiveTodos$),
constant('/completed', showCompletedTodos$),
)
const { router } = Router(CaptureClicks(History)({ history$ }))
const routes =
{
'/active': map(filterCompleted, todos$),
'/completed': map(filterActive, todos$),
'*': todos$,
}
const defineReturn$ = define(routes, router)
const filteredTodos$ =
switchLatest(map>>((x) => x.value, defineReturn$))
export function FilterTodos(sinks: Sinks): Sources {
const { showActiveTodos$, showAllTodos$, showCompletedTodos$, todos$ } = sinks
const history$ =
merge(
constant('/', showAllTodos$),
constant('/active', showActiveTodos$),
constant('/completed', showCompletedTodos$),
)
const { router } = Router(CaptureClicks(History)({ history$ }))
const routes =
{
'/active': map(filterCompleted, todos$),
'/completed': map(filterActive, todos$),
'*': todos$,
}
const defineReturn$ = define(routes, router)
const filteredTodos$ =
switchLatest(map>>((x) => x.value, defineReturn$))
export function LocalStorage(sinks: LocalStorageSinks): LocalStorageSources {
const { localStorage$ } = sinks
const localStorageEvent$: Stream =
filter(isLocalStorageEvent, fromEvent('storage', window, true))
const storage$: Stream =
multicast(merge(
constant(window.localStorage, tap(storageAction, localStorage$)),
constant(window.localStorage, localStorageEvent$),
))
drain(storage$)
const getItem = createGetItem(storage$)
const length = createLength(storage$)
const localStorage: LocalStorageSource =
{
getItem,
length,
}
return { localStorage }
}
export function FilterTodos(sinks: Sinks): Sources {
const { showActiveTodos$, showAllTodos$, showCompletedTodos$, todos$ } = sinks
const history$ =
merge(
constant('/', showAllTodos$),
constant('/active', showActiveTodos$),
constant('/completed', showCompletedTodos$),
)
const { router } = Router(CaptureClicks(History)({ history$ }))
const routes =
{
'/active': map(filterCompleted, todos$),
'/completed': map(filterActive, todos$),
'*': todos$,
}
const defineReturn$ = define(routes, router)
const filteredTodos$ =
export function SessionStorage(sinks: SessionStorageSinks): SessionStorageSources {
const { sessionStorage$ } = sinks
const storage$: Stream =
multicast(constant(window.sessionStorage, tap(storageAction, sessionStorage$)))
drain(storage$)
const getItem = createGetItem(storage$)
const length = createLength(storage$)
const sessionStorage: SessionStorageSource =
{
getItem,
length,
}
return { sessionStorage }
}
export function remove(dom: DomSource): Stream {
const destroy = query(`.${TodoItemStyles.destroyClass}`, dom)
const click$ = events('click', destroy)
return constant(true, click$)
}
const label = query(`.${TodoItemStyles.labelClass}`, dom)
const input = query(`.${TodoItemStyles.editClass}`, dom)
const blur$ = events('blur', input)
const dblClick$ = events('dblclick', label)
const keyDown$ = events('keydown', input)
const enterKey$ =
tap((event) => event.preventDefault(), filter(isEnterKey, keyDown$))
const editing$ =
hold(startWith(false, merge(
constant(false, enterKey$),
constant(true, dblClick$),
constant(false, blur$),
)))
const value$ =
map(trimmedValue, filter(isItemFilled, merge(enterKey$, blur$)))
return { editing$, value$ }
}
export function LocalStorage(sinks: LocalStorageSinks): LocalStorageSources {
const { localStorage$ } = sinks
const localStorageEvent$: Stream =
filter(isLocalStorageEvent, fromEvent('storage', window, true))
const storage$: Stream =
multicast(merge(
constant(window.localStorage, tap(storageAction, localStorage$)),
constant(window.localStorage, localStorageEvent$),
))
drain(storage$)
const getItem = createGetItem(storage$)
const length = createLength(storage$)
const localStorage: LocalStorageSource =
{
getItem,
length,
}
return { localStorage }
}