Skip to content

Commit

Permalink
feat(💧 BlueRainApp): Create basic BlueRain main app structure
Browse files Browse the repository at this point in the history
  • Loading branch information
artalat committed Sep 19, 2018
1 parent e626e99 commit f0dbedc
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 15 deletions.
13 changes: 0 additions & 13 deletions src/BlueRain.ts

This file was deleted.

38 changes: 38 additions & 0 deletions src/BlueRain.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ComponentRegistry, HookRegistry, PluginRegistry } from './registries';
import { BlueRainProvider } from './Context';
import { Logger } from './api';
import { register as registerInternalComponents } from './components';
import React from 'react';

export class BlueRain {

// APIs
public Logger = new Logger(this);

// Registries
public Components: ComponentRegistry = new ComponentRegistry(this);
public Hooks: HookRegistry = new HookRegistry(this);
public Plugins: PluginRegistry = new PluginRegistry(this);

// Flags
public booted = false;

public async boot() {

await registerInternalComponents(this);

// Set View
// const SystemApp = this.Components.resolve('SystemApp');
// SystemApp = await this.Hooks.run('bluerain.system.app', SystemApp);

const BluerainApp = () => (
<BlueRainProvider value={this}>
<this.Components.SystemApp />
</BlueRainProvider>
);

this.booted = true;

return BluerainApp;
}
}
43 changes: 43 additions & 0 deletions src/BlueRainApp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { BR } from './instance';
import React from 'react';

export interface BlueRainAppProperties {

// plugins: Plugin[]
}

interface BlueRainAppState {

booted: boolean;

Component: React.ComponentType<any>
}

export class BlueRainApp extends React.Component<BlueRainAppProperties, BlueRainAppState> {

state = {
booted: BR.booted,

Component: () => <div>Loading</div>
};

async componentDidMount() {
try {
const Component = await BR.boot();
this.setState({
Component,
booted: BR.booted,
});
} catch (error) {
// tslint:disable-next-line:no-console
console.error(error);
}
}

render() {

const Component = this.state.Component;

return <Component />;
}
}
1 change: 0 additions & 1 deletion src/BlueRainComponent.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/Context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BR } from './instance';
import { createContext } from 'react';

export const BlueRainContext = createContext(BR);
export const BlueRainProvider = BlueRainContext.Provider;
export const BlueRainConsumer = BlueRainContext.Consumer;
8 changes: 8 additions & 0 deletions src/components/SystemApp/SystemApp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';

export class SystemApp extends React.PureComponent {

render() {
return 'BlueRain System App!';
}
}
1 change: 1 addition & 0 deletions src/components/SystemApp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './SystemApp';
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './register';
7 changes: 7 additions & 0 deletions src/components/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BlueRain } from '../BlueRain';
import { SystemApp } from './SystemApp';

export async function register(BR: BlueRain) {

await BR.Components.register('SystemApp', SystemApp);
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export * from './BlueRain';
export * from './BlueRainApp';
export * from './Context';
export * from './instance';
export * from './registries';
3 changes: 3 additions & 0 deletions src/instance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { BlueRain } from './BlueRain';

export const BR = new BlueRain();
2 changes: 1 addition & 1 deletion src/registries/ComponentRegistry/ComponentRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class ComponentRegistry extends Registry<ComponentRegistryItem> {
}


public resolve(name: string) {
public resolve(name: string): React.ComponentType<any> {

const registryItem = super.get(name);

Expand Down

0 comments on commit f0dbedc

Please sign in to comment.