frintjs/frint

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

Open

#373 aperta il 14 nov 2017

Vedi su GitHub
 (0 commenti) (2 reazioni) (0 assegnatari)JavaScript (37 fork)batch import
featurehelp wanted

Metriche repository

Star
 (746 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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.

Guida contributor