Домены

Краткая справка

Группировка юнитов

const domain = createDomain();

const event = domain.createEvent();
const $store = domain.createStore();
const effectFx = domain.createEffect();

const childDomain = domain.createDomain();

Доступ до юнитов

const domain = createDomain()

const {
  domains,
  events,
  effects,
  stores
} = domain.history;

for (const event of events) {
  // do something with each event
}

Хуки

const domain = createDomain();

domain.onCreateEvent(event => {
  // do something with event
});

domain.onCreateStore(store => {
  // do something with store
});

domain.onCreateEffect(effect => {
  // do something with effect
});

domain.onCreateDomain(domain => {
  // do something with domain
});

Дочерние домены

const domain = createDomain()

domain.onCreateEvent(event => console.log(event))

const childDomain = domain.createDomain()
const event = childDomain.createEvent()

// event WILL be printed in console

Юзкейсы

из наших приложений

Мониторинг

function collectEffectorMetrics({ domain }) {
  const { effects } = domain.history;

  effects.forEach((effect) => {
    countEffectFailure(effect);
    measureEffectDuration(effect);
  });
}

Логирование

конкретного сервиса

import { attachLogger } from 'effector-logger';

attachLogger(domain);

Массовые связи

в конкретном сервисе

const userServiceDomain = createDomain();

const logout = userServiceDomain.createEvent();

userServiceDomain.onCreateStore(store => {
  store.reset(logout)
});

const $email = userServiceDomain.createStore(null);
const $username = userServiceDomain.createStore(null);

Рут

Доступ до всех юнитов в приложении

import { root } from 'effector-root';

const allEventsInTheApplication = root.history.events;

Никакой магии

// effector-root source code

import { createDomain } from 'effector';

const rootDomain = createDomain('root', {
  name: 'root',
  sid: 'effector-root'
})

export * from 'effector';

export {
  createDomain: rootDomain.createDomain,
  createEffect: rootDomain.createEffect,
  createEvent: rootDomain.createEvent,
  createStore: rootDomain.createStore,
  rootDomain as root,
};

Никакой магии

// babel config

module.exports = {
  plugins: [
    [
    'babel-plugin-module-resolver',
      {
        root: ['.'],
        alias: {
          effector: 'effector-root',
        },
      },
    ],
  ]
}

Используйте домены

с наслаждением

Домены

By Igor Kamyshev

Домены

  • 185