BLoC snippets for React
ts/tsx, js/jsx 代码提示
import { $1 } from "react-bloc";
private _$1 = $2;
public $1$ = new EnhanceSubject(this._$1);
private _$1 = $2;
public $1$ = new EnhanceSubject(this._$1);
public set $1(obj: any) {
this._$1 = clone(obj);
this.$1$.add(this._$1);
}
public get $1() {
return this.$1$.value;
}
const _bloc = container.get<IBloc>(BLOC_TYPES.$1Bloc);
const _bloc = BlocProvider.of<$1Bloc>(BLOC_TYPES.$1Bloc);
<BlocProvider bloc={${1:_bloc}} child={$2} />
<BlocProvider blocs={[${1:_bloc}]} child={$2} />
<StreamBuilder stream={$1} builder={$2} />
function _$1Builder(snapshot: ISnapshot<$2>) {
return $3;
}
/**
* Created by MeePwn
* https://github.com/maybewaityou
*
* description:
*
*/
import { IDataSource } from "react-bloc";
export default interface I$1DataSource extends IDataSource {}
/**
* Created by MeePwn
* https://github.com/maybewaityou
*
* description:
*
*/
import { ILocalDataSource } from "react-bloc";
import { injectable, inject } from "inversify";
import { PROCESSOR } from "@arch";
import { DBService } from "@service";
import I$1DataSource from "../I$1DataSource";
export interface I$1LocalDataSource extends ILocalDataSource, I$1DataSource {}
@injectable()
export class $1LocalDataSource implements I$1LocalDataSource {
@inject(PROCESSOR.DBService)
private dbService: DBService;
}
/**
* Created by MeePwn
* https://github.com/maybewaityou
*
* description:
*
*/
import { IRemoteDataSource } from "react-bloc";
import { injectable, inject } from "inversify";
import { PROCESSOR } from "@arch";
import { WebService } from "@service";
import I$1DataSource from "../I$1DataSource";
export interface I$1RemoteDataSource extends IRemoteDataSource, I$1DataSource {}
@injectable()
export class $1RemoteDataSource implements I$1RemoteDataSource {
@inject(PROCESSOR.WebService)
private webService: WebService;
}
/**
* Created by MeePwn
* https://github.com/maybewaityou
*
* description:
*
*/
import { IRepository } from "react-bloc";
import { injectable, inject } from "inversify";
import { StrategyProcessor } from "@arch";
import { DATA_SOURCE_TYPES } from "../../ioc/types";
import I$1DataSource from "./I$1DataSource";
import { I$1LocalDataSource } from "../source/local/$1LocalDataSource";
import { I$1RemoteDataSource } from "../source/remote/$1RemoteDataSource";
@injectable()
export default class $1Repository implements IRepository, I$1DataSource {
@inject(DATA_SOURCE_TYPES.$1RemoteDataSource)
private remoteDataSource: I$1RemoteDataSource;
@inject(DATA_SOURCE_TYPES.$1LocalDataSource)
private localDataSource: I$1LocalDataSource;
}
const _local = this.localDataSource;
const _remote = this.remoteDataSource;
return new (class extends StrategyProcessor {
protected loadFromDb(): Promise<$1> {
return $2;
}
protected shouldFetch(data?: $1): boolean {
return data === undefined;
}
protected createService(): Promise<$1> {
return $3;
}
protected saveResult(data: $1): void {
$4;
}
})().process();
/**
* Created by MeePwn
* https://github.com/maybewaityou
*
* description:
*
*/
import { injectable, inject } from "inversify";
import { UseCase } from "@arch";
import { REPOSITORY_TYPES } from "../ioc/types";
import I$1UseCase from "./interactor/I$1UseCase";
import I$1DataSource from "../data/source/I$1DataSource";
@injectable()
export default class $1UseCase extends UseCase implements I$1UseCase {
@inject(REPOSITORY_TYPES.$1Repository)
private repository: I$1DataSource;
public buildUseCasePromise() {
return Promise.resolve();
}
}
this._${1:viewObj} = processModify(this._${1:viewObj}, $2);
this.${1:viewObj}$.add(this._${1:viewObj});
/**
* Created by MeePwn
* https://github.com/maybewaityou
*
* description:
*
*/
import { EnhanceSubject, processModify } from "react-bloc";
import { injectable, inject } from "inversify";
import { router } from "mario-navigation-extension";
import { Bloc } from "@arch";
import { clone } from "@utilities";
import { BLOC_TYPES, USE_CASE_TYPES } from "./ioc/types";
import { I$1UseCase } from "./interactor/index";
@injectable()
export default class $1Bloc extends Bloc {
@inject(USE_CASE_TYPES.$1UseCase)
private useCase: I$1UseCase;
public token() {
return BLOC_TYPES.$1Bloc;
}
}
/**
* Created by MeePwn
* https://github.com/maybewaityou
*
* description:
*
*/
import React from "react";
import {
StyleSheet,
Button,
Image,
ImageStyle,
Text,
TextStyle,
View,
ViewStyle
} from "react-native";
import { BlocProvider, IBloc, StreamBuilder, ISnapshot } from "react-bloc";
import { container } from "@arch";
import { $2Bloc, BLOC_TYPES } from "../bloc/index";
interface IStyle {
container: ViewStyle;
}
export default () => {
const _bloc = container.get<IBloc>(BLOC_TYPES.$1Bloc);
return <BlocProvider bloc={_bloc} child={_viewBuilder} />;
};
function _viewBuilder() {
return <View style={styles.container}></View>;
}
const styles = StyleSheet.create<IStyle>({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center"
}
});