How to use the effector.combine function in effector

To help you get started, we’ve selected a few effector examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github howtocards / frontend / src / pages / settings / model.js View on Github external
(settings, enteredEmail) =>
    createUrl(
      filterName(enteredEmail) ||
        settings?.gravatarEmail ||
        settings?.currentEmail ||
        defaultAvatar,
    ),
)

export const $nameChanged: Store = combine(
  $settings,
  $name,
  (settings, name) => (settings?.displayName || "") !== filterName(name),
)

export const $avaEmailChanged: Store = combine(
  $settings,
  $avaEmail,
  // just remove spaces from email
  (settings, email) => (settings?.gravatarEmail || "") !== filterName(email),
)

forward({
  from: pageMounted,
  to: loadSettings,
})

loadSettings.use(accountApi.getSettings)
saveSettings.use(accountApi.updateSettings)

forward({ from: saveSettings.done, to: loadSession })
github howtocards / frontend / src / pages / settings / model.js View on Github external
export const $isDisabled: Store = combine(
  $isSettingsReady,
  $isLoading,
  (ready, loading) => !ready || loading,
)

// Stores for inputs

const defaultAvatar =
  "https://www.gravatar.com/avatar/00000000000000000000000000000000?d=mp&s=512"
const avatarParams = "d=retro&rating=g&s=512"

export const $name: Store = createStore("")
export const $avaEmail: Store = createStore("")

export const $avatarUrl: Store = combine(
  $settings,
  $avaEmail,
  (settings, enteredEmail) =>
    createUrl(
      filterName(enteredEmail) ||
        settings?.gravatarEmail ||
        settings?.currentEmail ||
        defaultAvatar,
    ),
)

export const $nameChanged: Store = combine(
  $settings,
  $name,
  (settings, name) => (settings?.displayName || "") !== filterName(name),
)
github zerobias / effector / examples / serverless-ssr / src / app.tsx View on Github external
<h3>Users:</h3>
    
    
  
)

export const installHistory = app.createEvent()
const changeLocation = app.createEvent()

// triggered when current location not equal new location
// and new location is valid user ID
const onValidLocation = guard(changeLocation, {
  filter: sample({
    source: combine({loc: location$, users: userList}),
    clock: changeLocation,
    fn: ({loc, users}, path) =&gt;
      loc !== path &amp;&amp; users.includes(path.replace('/user/', '')),
  }),
})

installHistory.watch(history =&gt; {
  const locationUpdate = scopeBind(changeLocation)
  history.listen(location =&gt; {
    locationUpdate(location.pathname)
  })
})

forward({
  from: startClient,
  to: installHistory,
github howtocards / frontend / src / pages / settings / model.js View on Github external
export const $name: Store = createStore("")
export const $avaEmail: Store = createStore("")

export const $avatarUrl: Store = combine(
  $settings,
  $avaEmail,
  (settings, enteredEmail) =&gt;
    createUrl(
      filterName(enteredEmail) ||
        settings?.gravatarEmail ||
        settings?.currentEmail ||
        defaultAvatar,
    ),
)

export const $nameChanged: Store = combine(
  $settings,
  $name,
  (settings, name) =&gt; (settings?.displayName || "") !== filterName(name),
)

export const $avaEmailChanged: Store = combine(
  $settings,
  $avaEmail,
  // just remove spaces from email
  (settings, email) =&gt; (settings?.gravatarEmail || "") !== filterName(email),
)

forward({
  from: pageMounted,
  to: loadSettings,
})
github howtocards / frontend / src / pages / users / current / model.js View on Github external
$user.on(loadUser.done, (_, { result: user }) =&gt; user)
$cards.on(loadCards.done, (_, { result: { useful, created } }) =&gt; ({
  useful: useful.map(({ id }) =&gt; id),
  created: created.map(({ id }) =&gt; id),
}))

$cardsRegistry.on(
  loadCards.done,
  (registry, { result: { useful, created } }) =&gt; ({
    ...registry,
    ...cardsToObject(useful),
    ...cardsToObject(created),
  }),
)

export const $isLoading: Store = combine(
  userFetching.isLoading,
  cardsFetching.isLoading,
  (userLoading, cardsLoading) =&gt; userLoading || cardsLoading,
)

export const $isFailed: Store = combine(
  userFetching.isFailed,
  cardsFetching.isFailed,
  (userFailed, cardsFailed) =&gt; userFailed || cardsFailed,
)

export const $error: Store = combine(
  userFetching.isFailed,
  userFetching.error,
  cardsFetching.isFailed,
  cardsFetching.error,
github howtocards / frontend / src / pages / join / registration / model.js View on Github external
(value) =&gt; value === null,
)

export const $form = createStoreObject({
  email: $email,
  password: $password,
})

const $isFormValid = combine(
  $isPasswordCorrect,
  $isEmailCorrect,
  (isPasswordCorrect, isEmailCorrect) =&gt; isPasswordCorrect &amp;&amp; isEmailCorrect,
)

export const $isFormDisabled = registerFetching.isLoading
export const $isSubmitEnabled: Store = combine(
  $isFormValid,
  registerFetching.isLoading,
  (isFormValid, isregisterFetching) =&gt; isFormValid &amp;&amp; !isregisterFetching,
)

sample($isAuthenticated, formMounted).watch((isAuthenticated) =&gt; {
  if (isAuthenticated) history.replace("/")
})

const trimEvent = (event) =&gt; event.currentTarget.value.trim()

$email.on(emailChanged.map(trimEvent), (_, email) =&gt; email)
$password.on(passwordChanged.map(trimEvent), (_, password) =&gt; password)
$form.reset(formUnmounted).reset(formMounted)

sample(
github DTupalov / react-material-ui-datatable / src / model / createComputedData.js View on Github external
export default ($data, $columns, $sort, $searchValue, $filterValues) => {
  const $computedData = combine(
    $data,
    $columns,
    $sort,
    $searchValue,
    $filterValues,
    (data, columns, sort, searchValue, filterValues) =>
      pipe(
        sortFn(sort),
        search(searchValue, columns),
        filter(filterValues, columns)
      )(data)
  );

  return { $computedData };
};
github howtocards / frontend / src / pages / view / model.js View on Github external
export const pageUnloaded = createEvent()

export const cardLoading: Effect&lt;
  { cardId: number },
  { card: Card },
  void,
&gt; = createEffect()
export const cardFetching: Fetching&lt;*, void&gt; = createFetching(
  cardLoading,
  "loading",
)

const $cardId = createStore(-1)

export const $card: Store = combine(
  $cardsRegistry,
  $cardId,
  (registry, cardId) =&gt; registry[cardId],
)

cardLoading.use(({ cardId }) =&gt; cardsApi.getById(cardId))

$cardId.on(cardLoading, (_, { cardId }) =&gt; cardId)
$cardId.on(cardLoading.done, (_, { result }) =&gt; result.card.id)
$cardId.reset(pageUnloaded)

$cardsRegistry.on(cardLoading.done, (registry, { result }) =&gt; {
  return {
    ...registry,
    ...cardsToObject([result.card]),
  }
github zerobias / effector / website / editor / src / view.js View on Github external
{...stats}
    /&gt;
  ),
)

const ErrorsView = createComponent(
  codeError,
  ({}, {isError, error, stackFrames}) =&gt; (
    
  ),
)

const changeSourcesDebounced = debounce(changeSources, 500)
const CodeView = createComponent(
  {
    displayEditor: combine(tab, isDesktopChanges, (tab, isDesktop) =&gt;
      isDesktop ? true : tab === 'editor',
    ),
    sourceCode,
    mode,
  },
  ({}, {displayEditor, mode, sourceCode}) =&gt; (
    <div style="{{visibility:">
      </div>
github howtocards / frontend / src / pages / join / login / model.js View on Github external
export const $password = createStore("")
export const $passwordError = $password.map((value) =&gt; {
  if (value &amp;&amp; value.length &gt; 1) return null
  return "Please, enter password"
})
export const $isPasswordCorrect = $passwordError.map(
  (value) =&gt; value === null,
)

export const $form = createStoreObject({
  email: $email,
  password: $password,
})

const $isFormValid = combine(
  $isPasswordCorrect,
  $isEmailCorrect,
  (isPasswordCorrect, isEmailCorrect) =&gt; isPasswordCorrect &amp;&amp; isEmailCorrect,
)

export const $isFormDisabled = loginFetching.isLoading
export const $isSubmitEnabled: Store = combine(
  $isFormValid,
  loginFetching.isLoading,
  (isFormValid, isLoginFetching) =&gt; isFormValid &amp;&amp; !isLoginFetching,
)

formMounted.watch(() =&gt; {
  if ($isAuthenticated.getState()) {
    history.replace("/")
  }