@bloc-js/react-bloc
Advanced tools
Comparing version 2.0.3 to 2.0.4
import { Bloc } from "@bloc-js/bloc"; | ||
export declare type CreateBlocFn<S> = () => Bloc<S>; | ||
export declare function useBlocState<S>(blocCreator: Bloc<S> | CreateBlocFn<S>): S; | ||
export declare function useBlocState<S>(blocCreator: Bloc<S> | CreateBlocFn<S>): S | null; |
@@ -1,15 +0,7 @@ | ||
import { useEffect, useState, useRef } from "react"; | ||
import { useEffect, useState } from "react"; | ||
export function useBlocState(blocCreator) { | ||
var blocRef = useRef(); | ||
function getBloc() { | ||
if (blocRef.current) | ||
return blocRef.current; | ||
blocRef.current = | ||
typeof blocCreator === "function" ? blocCreator() : blocCreator; | ||
return blocRef.current; | ||
} | ||
var _a = useState(getBloc().value), state = _a[0], setState = _a[1]; | ||
var _a = useState(null), state = _a[0], setState = _a[1]; | ||
useEffect(function () { | ||
var shouldDispose = typeof blocCreator === "function"; | ||
var bloc = getBloc(); | ||
var bloc = typeof blocCreator === "function" ? blocCreator() : blocCreator; | ||
setState(bloc.value); | ||
@@ -16,0 +8,0 @@ var subscription = bloc.subscribe(function (nextState) { |
import { Bloc } from "@bloc-js/bloc"; | ||
export declare type CreateBlocFn<S> = () => Bloc<S>; | ||
export declare function useBlocState<S>(blocCreator: Bloc<S> | CreateBlocFn<S>): S; | ||
export declare function useBlocState<S>(blocCreator: Bloc<S> | CreateBlocFn<S>): S | null; |
@@ -1,15 +0,7 @@ | ||
import { useEffect, useState, useRef } from "react"; | ||
import { useEffect, useState } from "react"; | ||
export function useBlocState(blocCreator) { | ||
const blocRef = useRef(); | ||
function getBloc() { | ||
if (blocRef.current) | ||
return blocRef.current; | ||
blocRef.current = | ||
typeof blocCreator === "function" ? blocCreator() : blocCreator; | ||
return blocRef.current; | ||
} | ||
const [state, setState] = useState(getBloc().value); | ||
const [state, setState] = useState(null); | ||
useEffect(() => { | ||
const shouldDispose = typeof blocCreator === "function"; | ||
const bloc = getBloc(); | ||
const bloc = typeof blocCreator === "function" ? blocCreator() : blocCreator; | ||
setState(bloc.value); | ||
@@ -16,0 +8,0 @@ const subscription = bloc.subscribe(nextState => { |
import { Bloc } from "@bloc-js/bloc"; | ||
export declare type CreateBlocFn<S> = () => Bloc<S>; | ||
export declare function useBlocState<S>(blocCreator: Bloc<S> | CreateBlocFn<S>): S; | ||
export declare function useBlocState<S>(blocCreator: Bloc<S> | CreateBlocFn<S>): S | null; |
@@ -5,14 +5,6 @@ "use strict"; | ||
function useBlocState(blocCreator) { | ||
var blocRef = react_1.useRef(); | ||
function getBloc() { | ||
if (blocRef.current) | ||
return blocRef.current; | ||
blocRef.current = | ||
typeof blocCreator === "function" ? blocCreator() : blocCreator; | ||
return blocRef.current; | ||
} | ||
var _a = react_1.useState(getBloc().value), state = _a[0], setState = _a[1]; | ||
var _a = react_1.useState(null), state = _a[0], setState = _a[1]; | ||
react_1.useEffect(function () { | ||
var shouldDispose = typeof blocCreator === "function"; | ||
var bloc = getBloc(); | ||
var bloc = typeof blocCreator === "function" ? blocCreator() : blocCreator; | ||
setState(bloc.value); | ||
@@ -19,0 +11,0 @@ var subscription = bloc.subscribe(function (nextState) { |
{ | ||
"name": "@bloc-js/react-bloc", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "React components for implementing the BLoC pattern.", | ||
@@ -49,3 +49,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "4da75e6325064f229d4986685b1a08da0dc9d4fc" | ||
"gitHead": "20ec2962c4d6142893cef84ab41d44132b706730" | ||
} |
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
11811
140