frintjs/frint

frint-router-react: Support rendering already registered Apps by name

開放

#373 建立於 2017年11月14日

 (0 則留言) (2 個反應) (0 位負責人)JavaScript (37 個分叉)batch import
featurehelp wanted

倉庫指標

星標
 (746 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

Currently

Along with Components, we also support rendering Apps with <Route>:

import { Route } from 'frint-router-react';

import MyApp from './apps/MyApp';

function MyComponent() {
  return (
    <div>
      <Route path="/about" app={MyApp} />
    </div>
  );
}

Whenever the route is active, it handles instantiating the App and then rendering it. And when the route is not active and unmounted, it will destroy the App instance.

Proposed feature

FrintJS allows Child Apps to be registered:

window.app.registerApp(MyApp);

This instantiates the App and keeps it in the local registry.

We can re-use the same instance in routing too if needed:

import { Route } from 'frint-router-react';

function MyComponent() {
  return (
    <div>
      <Route path="/about" app="MyApp" />
    </div>
  );
}

Instead of supporting only classes for app, we can also additionally support strings (App names). This way, routes can be enabled to render the same App's instance and they don't need to instantiated/destroyed every time the Route becomes active.

It gives developers a choice based on their needs.

貢獻者指南