Skip to content

Commit f0dbedc

Browse files
committed
feat(💧 BlueRainApp): Create basic BlueRain main app structure
1 parent e626e99 commit f0dbedc

File tree

12 files changed

+111
-15
lines changed

12 files changed

+111
-15
lines changed

src/BlueRain.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/BlueRain.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { ComponentRegistry, HookRegistry, PluginRegistry } from './registries';
2+
import { BlueRainProvider } from './Context';
3+
import { Logger } from './api';
4+
import { register as registerInternalComponents } from './components';
5+
import React from 'react';
6+
7+
export class BlueRain {
8+
9+
// APIs
10+
public Logger = new Logger(this);
11+
12+
// Registries
13+
public Components: ComponentRegistry = new ComponentRegistry(this);
14+
public Hooks: HookRegistry = new HookRegistry(this);
15+
public Plugins: PluginRegistry = new PluginRegistry(this);
16+
17+
// Flags
18+
public booted = false;
19+
20+
public async boot() {
21+
22+
await registerInternalComponents(this);
23+
24+
// Set View
25+
// const SystemApp = this.Components.resolve('SystemApp');
26+
// SystemApp = await this.Hooks.run('bluerain.system.app', SystemApp);
27+
28+
const BluerainApp = () => (
29+
<BlueRainProvider value={this}>
30+
<this.Components.SystemApp />
31+
</BlueRainProvider>
32+
);
33+
34+
this.booted = true;
35+
36+
return BluerainApp;
37+
}
38+
}

src/BlueRainApp.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { BR } from './instance';
2+
import React from 'react';
3+
4+
export interface BlueRainAppProperties {
5+
6+
// plugins: Plugin[]
7+
}
8+
9+
interface BlueRainAppState {
10+
11+
booted: boolean;
12+
13+
Component: React.ComponentType<any>
14+
}
15+
16+
export class BlueRainApp extends React.Component<BlueRainAppProperties, BlueRainAppState> {
17+
18+
state = {
19+
booted: BR.booted,
20+
21+
Component: () => <div>Loading</div>
22+
};
23+
24+
async componentDidMount() {
25+
try {
26+
const Component = await BR.boot();
27+
this.setState({
28+
Component,
29+
booted: BR.booted,
30+
});
31+
} catch (error) {
32+
// tslint:disable-next-line:no-console
33+
console.error(error);
34+
}
35+
}
36+
37+
render() {
38+
39+
const Component = this.state.Component;
40+
41+
return <Component />;
42+
}
43+
}

src/BlueRainComponent.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Context.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { BR } from './instance';
2+
import { createContext } from 'react';
3+
4+
export const BlueRainContext = createContext(BR);
5+
export const BlueRainProvider = BlueRainContext.Provider;
6+
export const BlueRainConsumer = BlueRainContext.Consumer;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
3+
export class SystemApp extends React.PureComponent {
4+
5+
render() {
6+
return 'BlueRain System App!';
7+
}
8+
}

src/components/SystemApp/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './SystemApp';

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './register';

src/components/register.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { BlueRain } from '../BlueRain';
2+
import { SystemApp } from './SystemApp';
3+
4+
export async function register(BR: BlueRain) {
5+
6+
await BR.Components.register('SystemApp', SystemApp);
7+
}

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
export * from './BlueRain';
2+
export * from './BlueRainApp';
3+
export * from './Context';
4+
export * from './instance';
25
export * from './registries';

src/instance.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { BlueRain } from './BlueRain';
2+
3+
export const BR = new BlueRain();

src/registries/ComponentRegistry/ComponentRegistry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class ComponentRegistry extends Registry<ComponentRegistryItem> {
8888
}
8989

9090

91-
public resolve(name: string) {
91+
public resolve(name: string): React.ComponentType<any> {
9292

9393
const registryItem = super.get(name);
9494

0 commit comments

Comments
 (0)