Bu sahifa hali tarjima qilinmagan

Tarjima qoshish uchun havola boyicha o'tib Pull Request oching (havolaga o'tish).

Standart til uchun tarkibni ko'rsatadi.

import { restore } from "effector";

Methods

restore(event, defaultState)

Creates a StoreWritable from an Event. It works like a shortcut for createStore(defaultState).on(event, (_, payload) => payload)

It is not a derived store

Restore creates a new store. It is not a DerivedStore. That means you can modify its state via events, and use it as target in sample.

Formulae

restore(event: Event<T>, defaultState: T): StoreWritable<T>

Arguments

  1. event Event
  2. defaultState (Payload)

Returns

StoreWritable: New store

Examples

Basic

import { createEvent, restore } from "effector";

const event = createEvent();
const $store = restore(event, "default");

$store.watch((state) => console.log("state: ", state));
// state: default

event("foo");
// state: foo

Try it

restore(effect, defaultState)

Creates a StoreWritable out of successful results of an Effect. It works like a shortcut for createStore(defaultState).on(effect.done, (_, {result}) => result)

Formulae

restore(effect: Effect<Params, Done, Fail>, defaultState: Done): StoreWritable<Done>

Arguments

  1. effect Effect
  2. defaultState (Done)

Returns

StoreWritable: New store

Types

Store will have the same type as Done from Effect<Params, Done, Fail>. Also, defaultState should have Done type.

Examples

Effect

import { createEffect, restore } from "effector";

const fx = createEffect(() => "foo");
const $store = restore(fx, "default");

$store.watch((state) => console.log("state: ", state));
// => state: default

await fx();
// => state: foo

Try it

restore(shape)

Creates an object with stores from an object with values.

Formulae

TBD

Arguments

  1. shape (State)

Returns

StoreWritable: New store.

Examples

Object

import { restore } from "effector";

const { foo: $foo, bar: $bar } = restore({
  foo: "foo",
  bar: 0,
});

$foo.watch((foo) => {
  console.log("foo", foo);
});
// => foo 'foo'
$bar.watch((bar) => {
  console.log("bar", bar);
});
// => bar 0

Try it

Tarjima jamiyat tomonidan qollanilyapti

Ingliz tilidagi hujjatlar eng dolzarb hisoblanadi, chunki u effector guruhi tomonidan yozilgan va yangilanadi. Hujjatlarni boshqa tillarga tarjima qilish jamiyat tomonidan kuch va istaklar mavjud bo'lganda amalga oshiriladi.

Esda tutingki, tarjima qilingan maqolalar yangilanmasligi mumkin, shuning uchun eng aniq va dolzarb ma'lumot uchun hujjatlarning asl inglizcha versiyasidan foydalanishni tavsiya etamiz.

Hammualliflar