项目作者: framework

项目描述 :
高级语言:
项目地址: git://github.com/framework/framework.git
创建时间: 2021-02-10T09:59:32Z
项目社区:https://github.com/framework/framework

开源协议:

下载


bypath

Simple framework for React, TypeScript and effector applications.

Installation

  1. npm install bypath

Usage

  1. // index.ts
  2. import { createBrowserApplication } from 'bypath';
  3. import { createEvent } from 'effector';
  4. import * as navigation from 'entities/navigation';
  5. import { routes } from './pages';
  6. const applicationLoaded = createEvent()
  7. const app = createBrowserApplication({
  8. routes,
  9. ready: applicationLoaded,
  10. domain: navigation.navigationDomain
  11. // domain is optional
  12. // for debug/logging
  13. });
  14. // connect local route events
  15. forward({
  16. from: navigation.historyPush,
  17. to: app.navigation.historyPush
  18. })
  19. forward({
  20. from: navigation.historyPushSearch,
  21. to: app.navigation.historyPushSearch
  22. })
  23. forward({
  24. from: navigation.historyReplace,
  25. to: app.navigation.historyReplace
  26. })
  1. // some-page/contract.ts
  2. import { createRoute } from 'bypath';
  3. import { navigationDomain } from 'entities/navigation';
  4. export const route = createRoute(navigationDomain);
  5. // domain is optional
  6. // for debug/logging
  1. // some-page/index.tsx
  2. import { sample, createDomain } from 'effector';
  3. import { withRoute } from 'bypath';
  4. import { historyPush } from 'entities/navigation';
  5. import { $isAuthenticated } from 'entities/session';
  6. import { route } from './contract';
  7. export const Page = withRoute(route, () => {
  8. //...
  9. });
  10. sample({
  11. source: route.enter,
  12. filter: $isAuthenticated.map((is) => !is),
  13. target: historyPush.prepend(() => '/login')
  14. });