@bloc-js/react-bloc
Advanced tools
Comparing version 1.3.0 to 2.0.0
/// <reference types="react" /> | ||
import { Bloc } from "@bloc-js/bloc"; | ||
export interface IBlocBuilderProps<S> { | ||
bloc: Bloc<any, S>; | ||
bloc: Bloc<S>; | ||
builder: (state: S) => JSX.Element; | ||
} | ||
export declare function BlocBuilder<S>(props: IBlocBuilderProps<S>): JSX.Element; |
import { useEffect, useState } from "react"; | ||
export function BlocBuilder(props) { | ||
var _a = useState(props.bloc.currentState), state = _a[0], setState = _a[1]; | ||
var _a = useState(props.bloc.value), state = _a[0], setState = _a[1]; | ||
useEffect(function () { | ||
var subscription = props.bloc.state$.subscribe(function (data) { | ||
var subscription = props.bloc.subscribe(function (data) { | ||
setState(data); | ||
@@ -7,0 +7,0 @@ }); |
import { Bloc } from "@bloc-js/bloc"; | ||
export declare type CreateBlocFn<S> = () => Bloc<any, S>; | ||
export declare function useBlocState<S>(blocCreator: Bloc<any, S> | CreateBlocFn<S>): S; | ||
export declare type CreateBlocFn<S> = () => Bloc<S>; | ||
export declare function useBlocState<S>(blocCreator: Bloc<S> | CreateBlocFn<S>): S; |
@@ -11,8 +11,8 @@ import { useEffect, useState, useRef } from "react"; | ||
} | ||
var _a = useState(getBloc().currentState), state = _a[0], setState = _a[1]; | ||
var _a = useState(getBloc().value), state = _a[0], setState = _a[1]; | ||
useEffect(function () { | ||
var shouldDispose = typeof blocCreator === "function"; | ||
var bloc = getBloc(); | ||
setState(bloc.currentState); | ||
var subscription = bloc.state$.subscribe(function (nextState) { | ||
setState(bloc.value); | ||
var subscription = bloc.subscribe(function (nextState) { | ||
setState(nextState); | ||
@@ -23,3 +23,3 @@ }); | ||
if (shouldDispose) | ||
bloc.dispose(); | ||
bloc.complete(); | ||
}; | ||
@@ -26,0 +26,0 @@ }, []); |
/// <reference types="react" /> | ||
import { Bloc } from "@bloc-js/bloc"; | ||
export interface IBlocBuilderProps<S> { | ||
bloc: Bloc<any, S>; | ||
bloc: Bloc<S>; | ||
builder: (state: S) => JSX.Element; | ||
} | ||
export declare function BlocBuilder<S>(props: IBlocBuilderProps<S>): JSX.Element; |
import { useEffect, useState } from "react"; | ||
export function BlocBuilder(props) { | ||
const [state, setState] = useState(props.bloc.currentState); | ||
const [state, setState] = useState(props.bloc.value); | ||
useEffect(() => { | ||
const subscription = props.bloc.state$.subscribe(data => { | ||
const subscription = props.bloc.subscribe(data => { | ||
setState(data); | ||
@@ -7,0 +7,0 @@ }); |
import { Bloc } from "@bloc-js/bloc"; | ||
export declare type CreateBlocFn<S> = () => Bloc<any, S>; | ||
export declare function useBlocState<S>(blocCreator: Bloc<any, S> | CreateBlocFn<S>): S; | ||
export declare type CreateBlocFn<S> = () => Bloc<S>; | ||
export declare function useBlocState<S>(blocCreator: Bloc<S> | CreateBlocFn<S>): S; |
@@ -11,8 +11,8 @@ import { useEffect, useState, useRef } from "react"; | ||
} | ||
const [state, setState] = useState(getBloc().currentState); | ||
const [state, setState] = useState(getBloc().value); | ||
useEffect(() => { | ||
const shouldDispose = typeof blocCreator === "function"; | ||
const bloc = getBloc(); | ||
setState(bloc.currentState); | ||
const subscription = bloc.state$.subscribe(nextState => { | ||
setState(bloc.value); | ||
const subscription = bloc.subscribe(nextState => { | ||
setState(nextState); | ||
@@ -23,3 +23,3 @@ }); | ||
if (shouldDispose) | ||
bloc.dispose(); | ||
bloc.complete(); | ||
}; | ||
@@ -26,0 +26,0 @@ }, []); |
/// <reference types="react" /> | ||
import { Bloc } from "@bloc-js/bloc"; | ||
export interface IBlocBuilderProps<S> { | ||
bloc: Bloc<any, S>; | ||
bloc: Bloc<S>; | ||
builder: (state: S) => JSX.Element; | ||
} | ||
export declare function BlocBuilder<S>(props: IBlocBuilderProps<S>): JSX.Element; |
@@ -5,5 +5,5 @@ "use strict"; | ||
function BlocBuilder(props) { | ||
var _a = react_1.useState(props.bloc.currentState), state = _a[0], setState = _a[1]; | ||
var _a = react_1.useState(props.bloc.value), state = _a[0], setState = _a[1]; | ||
react_1.useEffect(function () { | ||
var subscription = props.bloc.state$.subscribe(function (data) { | ||
var subscription = props.bloc.subscribe(function (data) { | ||
setState(data); | ||
@@ -10,0 +10,0 @@ }); |
import { Bloc } from "@bloc-js/bloc"; | ||
export declare type CreateBlocFn<S> = () => Bloc<any, S>; | ||
export declare function useBlocState<S>(blocCreator: Bloc<any, S> | CreateBlocFn<S>): S; | ||
export declare type CreateBlocFn<S> = () => Bloc<S>; | ||
export declare function useBlocState<S>(blocCreator: Bloc<S> | CreateBlocFn<S>): S; |
@@ -13,8 +13,8 @@ "use strict"; | ||
} | ||
var _a = react_1.useState(getBloc().currentState), state = _a[0], setState = _a[1]; | ||
var _a = react_1.useState(getBloc().value), state = _a[0], setState = _a[1]; | ||
react_1.useEffect(function () { | ||
var shouldDispose = typeof blocCreator === "function"; | ||
var bloc = getBloc(); | ||
setState(bloc.currentState); | ||
var subscription = bloc.state$.subscribe(function (nextState) { | ||
setState(bloc.value); | ||
var subscription = bloc.subscribe(function (nextState) { | ||
setState(nextState); | ||
@@ -25,3 +25,3 @@ }); | ||
if (shouldDispose) | ||
bloc.dispose(); | ||
bloc.complete(); | ||
}; | ||
@@ -28,0 +28,0 @@ }, []); |
{ | ||
"name": "@bloc-js/react-bloc", | ||
"version": "1.3.0", | ||
"version": "2.0.0", | ||
"description": "React components for implementing the BLoC pattern.", | ||
@@ -29,3 +29,3 @@ "keywords": [ | ||
"scripts": { | ||
"clean": "rm -rf lib", | ||
"clean": "rm -rf lib*", | ||
"tsc:es": "tsc -m es6 --outDir lib-es/", | ||
@@ -41,11 +41,12 @@ "tsc:esnext": "tsc -m esnext -t esnext --outDir lib-esnext/", | ||
"peerDependencies": { | ||
"@bloc-js/bloc": "*", | ||
"@bloc-js/bloc": ">= 2", | ||
"react": "*" | ||
}, | ||
"devDependencies": { | ||
"@bloc-js/bloc": "^1.7.0", | ||
"@bloc-js/bloc": "^2.0.0", | ||
"@types/react": "^16.8.18", | ||
"react": "^16.11.0" | ||
"react": "^16.11.0", | ||
"rxjs": "^6.5.3" | ||
}, | ||
"gitHead": "6ad9e20ee6be99f927485343e1d1a18b9fc8ceb8" | ||
"gitHead": "b5155d84f5c67705c37f668649a0d4cd46bfec8f" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
13066
4