frintjs / frint

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

frint: handle App lifecycle events without overriding options #381

Closed fahad19 closed 6 years ago

fahad19 commented 6 years ago

What's done

When defining and instantiating Apps, the lifecycle methods (initialize and beforeDestroy) will not be overridden any more.

This means, the methods you pass when creating an App, and also intantiating the App will both trigger.

Usage

import { createApp } from 'frint';

const RootApp = createApp({
  name: 'RootApp',
  initialize() {
    console.log('defined when creating App class');
  },
});

const app = new RootApp({
  initialize() {
    console.log('defined when instantiating the App');
  }
});

The above code will print two logs in this order:

defined when creating App class
defined when instantiating the App

What value does it bring?

The API will now allow us to wrap Child Apps' components with ease in a custom bundler level, as mentioned in #376.

We can now do something like:

window.app.registerApp(ChildApp, {
  initialize() {
    const existingComponent = this.get('component');
    const wrappedComponent = wrapItWithErrorBoundaryAndLogTheError(existingComponent);
    this.container.register({
      name: 'component',
      useValue: wrappedComponent,
    });
  },
});

You can see the examples in tests in the diff.

codecov[bot] commented 6 years ago

Codecov Report

Merging #381 into master will increase coverage by 0.01%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #381      +/-   ##
==========================================
+ Coverage   97.31%   97.33%   +0.01%     
==========================================
  Files         101      101              
  Lines        3871     3900      +29     
==========================================
+ Hits         3767     3796      +29     
  Misses        104      104
Impacted Files Coverage Δ
packages/frint/src/App.spec.js 100% <100%> (ø) :arrow_up:
packages/frint/src/createApp.js 100% <100%> (ø) :arrow_up:
...-component-handlers/src/createRouteHandler.spec.js 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update fe4c736...8f23ebb. Read the comment docs.