frintjs / frint

Modular JavaScript framework for building scalable and reactive applications
https://frint.js.org/
MIT License
756 stars 37 forks source link

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

Open fahad19 opened 6 years ago

fahad19 commented 6 years ago

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.