Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//@flow
import {createStoreObject} from 'effector'
import {mediaMatcher} from './mediaMatcher'
/* declaring queries and merge them into single store*/
export const screenQueries = createStoreObject({
small: mediaMatcher('(max-width: 768px)'),
medium: mediaMatcher('(min-width: 769px) and (max-width: 1024px)'),
large: mediaMatcher('(min-width: 1025px)'),
portrait: mediaMatcher('(orientation: portrait)'),
})
options: {className: 'CodeMirror-lint-mark-error'},
})
}
})
changeSources.map(compress).watch(code => {
localStorage.setItem('code-compressed', code)
})
forward({
from: changeSources,
to: sourceCode,
})
{
const initStore = createStoreObject({
sourceCode,
versionLoader,
typechecker,
})
initStore.watch(data => {
console.log('init store update', data)
evalEffect(data.sourceCode)
})
}
changeSources(retrieveCode())
selectVersion(retrieveVersion())
import { history } from "@lib/routing"
import { cardsApi, type Card } from "@api/cards"
export const titleChanged = createEvent>()
export const contentChanged = createEvent<*>()
export const formSubmitted = createEvent<*>()
export const pageUnmounted = createEvent()
const cardCreate = createEffect()
export const cardCreateFetching: Fetching = createFetching(cardCreate)
export const $title = createStore("")
export const $content = createStore<{}>(
Plain.deserialize("Start typing here...").toJS(),
)
const $form = createStoreObject({
title: $title,
content: $content,
})
const trimEvent = (event) => event.currentTarget.value
$title.on(titleChanged.map(trimEvent), (_, title) => title)
$content.on(contentChanged, (_, content) => content)
$form.reset(pageUnmounted)
formSubmitted.watch(() => {
cardCreate($form.getState())
})
cardCreate.use(cardsApi.create)
authKey: authKeyReducer,
auth: authReducer,
currentUser: currentUserReducer,
users,
peers,
selected,
histories,
avatars,
media,
photos,
photoSizes,
photoCachedSizes,
})
export const rootStore = createStoreObject({
messages,
dialogs,
documents,
chats,
theme,
loadings,
settings,
files,
})
export default rootReducer
export function inject(
stores: {[key in K]: Store},
): any {
const merged = createStoreObject(stores);
const Consumer = createStoreConsumer(merged);
return (
Cmp: React.ComponentType,
) => (props: Props & {[key in K]: typeof stores[key]}) => (
{state => }
);
}
registerProcessing,
)
export const $email = createStore("")
export const $emailError: Store = $email.map(emailValidator)
export const $isEmailCorrect = $emailError.map(
(value) => value === null,
)
export const $password = createStore("")
export const $passwordError: Store = $password.map(passwordValidator)
export const $isPasswordCorrect = $passwordError.map(
(value) => value === null,
)
export const $form = createStoreObject({
email: $email,
password: $password,
})
const $isFormValid = combine(
$isPasswordCorrect,
$isEmailCorrect,
(isPasswordCorrect, isEmailCorrect) => isPasswordCorrect && isEmailCorrect,
)
export const $isFormDisabled = registerFetching.isLoading
export const $isSubmitEnabled: Store = combine(
$isFormValid,
registerFetching.isLoading,
(isFormValid, isregisterFetching) => isFormValid && !isregisterFetching,
)
$data,
$columns,
$sort,
$searchValue,
$filterValues
);
const { $filterLists } = createFilterLists($data, $columns);
const { $displayData } = createDisplayData($computedData, $page, $perPage);
const {
$selectedData,
toggleSelectRow,
toggleSelectAll,
handleSelect,
} = createSelectedData(initialSelectedData, $computedData, handleDelete);
const $store = createStoreObject({
data: $data,
columns: $columns,
sort: $sort,
filterValues: $filterValues,
searchValue: $searchValue,
showSearchBar: $showSearchBar,
selectedData: $selectedData,
page: $page,
perPage: $perPage,
computedData: $computedData,
filterLists: $filterLists,
displayData: $displayData,
});
const actions = {
toggleSelectRow,
[key: string]: any
} = this
const key = 'state'
let shape = vm.$options.effector
if (typeof shape === 'function') {
shape = shape.call(vm)
}
if (shape) {
if (is.store(shape) /*:: && isStore(shape) */) {
//$off
Vue.util.defineReactive(vm, key, shape.getState())
vm._subscription = shape.subscribe(value => {
vm[key] = value
})
} else if (typeof shape === 'object' && shape !== null /*:: && !isStore(shape) */) {
const store = createStoreObject(shape)
for (const key in shape) {
//$off
Vue.util.defineReactive(vm, key, store.defaultState[key])
}
vm._subscription = store.subscribe(value => {
for (const key in value) {
vm[key] = value[key]
}
})
} else {
throw Error('property should be Store')
}
}
},
beforeDestroy() {
export const $email = createStore("")
export const $emailError = $email.map(emailValidator)
export const $isEmailCorrect = $emailError.map(
(value) => value === null,
)
export const $password = createStore("")
export const $passwordError = $password.map((value) => {
if (value && value.length > 1) return null
return "Please, enter password"
})
export const $isPasswordCorrect = $passwordError.map(
(value) => value === null,
)
export const $form = createStoreObject({
email: $email,
password: $password,
})
const $isFormValid = combine(
$isPasswordCorrect,
$isEmailCorrect,
(isPasswordCorrect, isEmailCorrect) => isPasswordCorrect && isEmailCorrect,
)
export const $isFormDisabled = loginFetching.isLoading
export const $isSubmitEnabled: Store = combine(
$isFormValid,
loginFetching.isLoading,
(isFormValid, isLoginFetching) => isFormValid && !isLoginFetching,
)
document: boolean,
video: boolean,
},
}
export const autoMediaDownload = createStore({
sticker: true,
photo: true,
voice: true,
round: true,
gif: true,
document: false,
video: false,
})
export const settings: Store = createStoreObject({
autoMediaDownload,
})