@bloc-js/react-bloc
Advanced tools
Comparing version 3.2.1 to 3.2.2
import * as React from "react"; | ||
import { Bloc } from "@bloc-js/bloc"; | ||
export declare class BlocRegistry { | ||
constructor(initialState?: { | ||
[id: string]: any; | ||
}); | ||
private blocs; | ||
private initialState; | ||
getState(): {}; | ||
register<S>(id: string, factory: TBlocFactory<S>): Bloc<S>; | ||
} | ||
import { BlocRegistry } from "./registry"; | ||
export declare const BlocRootContext: React.Context<BlocRegistry>; | ||
export declare type TBlocFactory<S> = (is?: S) => Bloc<S>; | ||
export declare type BlocGetter<S> = (registry: BlocRegistry) => Bloc<S>; | ||
export declare function blocGetter<S>(id: string, factory: TBlocFactory<S>): BlocGetter<S>; | ||
export interface BlocRootProps { | ||
@@ -17,0 +5,0 @@ registry: BlocRegistry; |
@@ -1,42 +0,4 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import * as React from "react"; | ||
var BlocRegistry = /** @class */ (function () { | ||
function BlocRegistry(initialState) { | ||
if (initialState === void 0) { initialState = {}; } | ||
this.blocs = {}; | ||
this.initialState = initialState; | ||
} | ||
BlocRegistry.prototype.getState = function () { | ||
var _this = this; | ||
return Object.keys(this.blocs).reduce(function (o, id) { | ||
var _a; | ||
return (__assign(__assign({}, o), (_a = {}, _a[id] = _this.blocs[id].value, _a))); | ||
}, {}); | ||
}; | ||
BlocRegistry.prototype.register = function (id, factory) { | ||
if (this.blocs[id]) { | ||
return this.blocs[id]; | ||
} | ||
var state = this.initialState[id]; | ||
var bloc = factory(state); | ||
this.blocs[id] = bloc; | ||
return bloc; | ||
}; | ||
return BlocRegistry; | ||
}()); | ||
export { BlocRegistry }; | ||
import { BlocRegistry } from "./registry"; | ||
export var BlocRootContext = React.createContext(new BlocRegistry({})); | ||
export function blocGetter(id, factory) { | ||
return function (registry) { return registry.register(id, factory); }; | ||
} | ||
export var BlocRoot = function (_a) { | ||
@@ -43,0 +5,0 @@ var children = _a.children, registry = _a.registry; |
import { Bloc } from "@bloc-js/bloc"; | ||
import { BlocGetter } from "./bloc-root"; | ||
import { BlocGetter, TBlocFactory } from "./registry"; | ||
export declare function useBloc<S>(fn: BlocGetter<S>): Bloc<S>; | ||
export declare function useBlocState<S>(bloc: Bloc<S>): S; | ||
export declare function createHooks<S>(id: string, factory: TBlocFactory<S>): { | ||
getBloc: BlocGetter<S>; | ||
useBloc: () => Bloc<S>; | ||
useState: () => S; | ||
}; |
import * as React from "react"; | ||
import { useEffect, useState } from "react"; | ||
import { BlocRootContext } from "./bloc-root"; | ||
import { blocGetter } from "./registry"; | ||
export function useBloc(fn) { | ||
@@ -21,2 +22,8 @@ var registry = React.useContext(BlocRootContext); | ||
} | ||
export function createHooks(id, factory) { | ||
var getBloc = blocGetter(id, factory); | ||
var useBlocHook = function () { return useBloc(getBloc); }; | ||
var useState = function () { return useBlocState(useBlocHook()); }; | ||
return { getBloc: getBloc, useBloc: useBlocHook, useState: useState }; | ||
} | ||
//# sourceMappingURL=hooks.js.map |
export * from "./bloc-builder"; | ||
export { BlocRootProps, BlocRoot } from "./bloc-root"; | ||
export * from "./hooks"; | ||
export * from "./registry"; | ||
export * from "./with-blocs"; | ||
export { BlocRegistry, TBlocFactory, BlocGetter, blocGetter, BlocRootProps, BlocRoot, } from "./bloc-root"; |
export * from "./bloc-builder"; | ||
export { BlocRoot } from "./bloc-root"; | ||
export * from "./hooks"; | ||
export * from "./registry"; | ||
export * from "./with-blocs"; | ||
export { BlocRegistry, blocGetter, BlocRoot, } from "./bloc-root"; | ||
//# sourceMappingURL=react-bloc.js.map |
import * as React from "react"; | ||
import { Bloc } from "@bloc-js/bloc"; | ||
export declare class BlocRegistry { | ||
constructor(initialState?: { | ||
[id: string]: any; | ||
}); | ||
private blocs; | ||
private initialState; | ||
getState(): {}; | ||
register<S>(id: string, factory: TBlocFactory<S>): Bloc<S>; | ||
} | ||
import { BlocRegistry } from "./registry"; | ||
export declare const BlocRootContext: React.Context<BlocRegistry>; | ||
export declare type TBlocFactory<S> = (is?: S) => Bloc<S>; | ||
export declare type BlocGetter<S> = (registry: BlocRegistry) => Bloc<S>; | ||
export declare function blocGetter<S>(id: string, factory: TBlocFactory<S>): BlocGetter<S>; | ||
export interface BlocRootProps { | ||
@@ -17,0 +5,0 @@ registry: BlocRegistry; |
import * as React from "react"; | ||
export class BlocRegistry { | ||
constructor(initialState = {}) { | ||
this.blocs = {}; | ||
this.initialState = initialState; | ||
} | ||
getState() { | ||
return Object.keys(this.blocs).reduce((o, id) => ({ | ||
...o, | ||
[id]: this.blocs[id].value, | ||
}), {}); | ||
} | ||
register(id, factory) { | ||
if (this.blocs[id]) { | ||
return this.blocs[id]; | ||
} | ||
const state = this.initialState[id]; | ||
const bloc = factory(state); | ||
this.blocs[id] = bloc; | ||
return bloc; | ||
} | ||
} | ||
import { BlocRegistry } from "./registry"; | ||
export const BlocRootContext = React.createContext(new BlocRegistry({})); | ||
export function blocGetter(id, factory) { | ||
return registry => registry.register(id, factory); | ||
} | ||
export const BlocRoot = ({ children, registry }) => (React.createElement(BlocRootContext.Provider, { value: registry }, children)); | ||
//# sourceMappingURL=bloc-root.js.map |
import { Bloc } from "@bloc-js/bloc"; | ||
import { BlocGetter } from "./bloc-root"; | ||
import { BlocGetter, TBlocFactory } from "./registry"; | ||
export declare function useBloc<S>(fn: BlocGetter<S>): Bloc<S>; | ||
export declare function useBlocState<S>(bloc: Bloc<S>): S; | ||
export declare function createHooks<S>(id: string, factory: TBlocFactory<S>): { | ||
getBloc: BlocGetter<S>; | ||
useBloc: () => Bloc<S>; | ||
useState: () => S; | ||
}; |
import * as React from "react"; | ||
import { useEffect, useState } from "react"; | ||
import { BlocRootContext } from "./bloc-root"; | ||
import { blocGetter } from "./registry"; | ||
export function useBloc(fn) { | ||
@@ -21,2 +22,8 @@ const registry = React.useContext(BlocRootContext); | ||
} | ||
export function createHooks(id, factory) { | ||
const getBloc = blocGetter(id, factory); | ||
const useBlocHook = () => useBloc(getBloc); | ||
const useState = () => useBlocState(useBlocHook()); | ||
return { getBloc, useBloc: useBlocHook, useState }; | ||
} | ||
//# sourceMappingURL=hooks.js.map |
export * from "./bloc-builder"; | ||
export { BlocRootProps, BlocRoot } from "./bloc-root"; | ||
export * from "./hooks"; | ||
export * from "./registry"; | ||
export * from "./with-blocs"; | ||
export { BlocRegistry, TBlocFactory, BlocGetter, blocGetter, BlocRootProps, BlocRoot, } from "./bloc-root"; |
export * from "./bloc-builder"; | ||
export { BlocRoot } from "./bloc-root"; | ||
export * from "./hooks"; | ||
export * from "./registry"; | ||
export * from "./with-blocs"; | ||
export { BlocRegistry, blocGetter, BlocRoot, } from "./bloc-root"; | ||
//# sourceMappingURL=react-bloc.js.map |
import * as React from "react"; | ||
import { Bloc } from "@bloc-js/bloc"; | ||
export declare class BlocRegistry { | ||
constructor(initialState?: { | ||
[id: string]: any; | ||
}); | ||
private blocs; | ||
private initialState; | ||
getState(): {}; | ||
register<S>(id: string, factory: TBlocFactory<S>): Bloc<S>; | ||
} | ||
import { BlocRegistry } from "./registry"; | ||
export declare const BlocRootContext: React.Context<BlocRegistry>; | ||
export declare type TBlocFactory<S> = (is?: S) => Bloc<S>; | ||
export declare type BlocGetter<S> = (registry: BlocRegistry) => Bloc<S>; | ||
export declare function blocGetter<S>(id: string, factory: TBlocFactory<S>): BlocGetter<S>; | ||
export interface BlocRootProps { | ||
@@ -17,0 +5,0 @@ registry: BlocRegistry; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
@@ -33,34 +22,6 @@ if (k2 === undefined) k2 = k; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BlocRoot = exports.blocGetter = exports.BlocRootContext = exports.BlocRegistry = void 0; | ||
exports.BlocRoot = exports.BlocRootContext = void 0; | ||
var React = __importStar(require("react")); | ||
var BlocRegistry = /** @class */ (function () { | ||
function BlocRegistry(initialState) { | ||
if (initialState === void 0) { initialState = {}; } | ||
this.blocs = {}; | ||
this.initialState = initialState; | ||
} | ||
BlocRegistry.prototype.getState = function () { | ||
var _this = this; | ||
return Object.keys(this.blocs).reduce(function (o, id) { | ||
var _a; | ||
return (__assign(__assign({}, o), (_a = {}, _a[id] = _this.blocs[id].value, _a))); | ||
}, {}); | ||
}; | ||
BlocRegistry.prototype.register = function (id, factory) { | ||
if (this.blocs[id]) { | ||
return this.blocs[id]; | ||
} | ||
var state = this.initialState[id]; | ||
var bloc = factory(state); | ||
this.blocs[id] = bloc; | ||
return bloc; | ||
}; | ||
return BlocRegistry; | ||
}()); | ||
exports.BlocRegistry = BlocRegistry; | ||
exports.BlocRootContext = React.createContext(new BlocRegistry({})); | ||
function blocGetter(id, factory) { | ||
return function (registry) { return registry.register(id, factory); }; | ||
} | ||
exports.blocGetter = blocGetter; | ||
var registry_1 = require("./registry"); | ||
exports.BlocRootContext = React.createContext(new registry_1.BlocRegistry({})); | ||
exports.BlocRoot = function (_a) { | ||
@@ -67,0 +28,0 @@ var children = _a.children, registry = _a.registry; |
import { Bloc } from "@bloc-js/bloc"; | ||
import { BlocGetter } from "./bloc-root"; | ||
import { BlocGetter, TBlocFactory } from "./registry"; | ||
export declare function useBloc<S>(fn: BlocGetter<S>): Bloc<S>; | ||
export declare function useBlocState<S>(bloc: Bloc<S>): S; | ||
export declare function createHooks<S>(id: string, factory: TBlocFactory<S>): { | ||
getBloc: BlocGetter<S>; | ||
useBloc: () => Bloc<S>; | ||
useState: () => S; | ||
}; |
@@ -22,6 +22,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.useBlocState = exports.useBloc = void 0; | ||
exports.createHooks = exports.useBlocState = exports.useBloc = void 0; | ||
var React = __importStar(require("react")); | ||
var react_1 = require("react"); | ||
var bloc_root_1 = require("./bloc-root"); | ||
var registry_1 = require("./registry"); | ||
function useBloc(fn) { | ||
@@ -46,2 +47,9 @@ var registry = React.useContext(bloc_root_1.BlocRootContext); | ||
exports.useBlocState = useBlocState; | ||
function createHooks(id, factory) { | ||
var getBloc = registry_1.blocGetter(id, factory); | ||
var useBlocHook = function () { return useBloc(getBloc); }; | ||
var useState = function () { return useBlocState(useBlocHook()); }; | ||
return { getBloc: getBloc, useBloc: useBlocHook, useState: useState }; | ||
} | ||
exports.createHooks = createHooks; | ||
//# sourceMappingURL=hooks.js.map |
export * from "./bloc-builder"; | ||
export { BlocRootProps, BlocRoot } from "./bloc-root"; | ||
export * from "./hooks"; | ||
export * from "./registry"; | ||
export * from "./with-blocs"; | ||
export { BlocRegistry, TBlocFactory, BlocGetter, blocGetter, BlocRootProps, BlocRoot, } from "./bloc-root"; |
@@ -14,8 +14,7 @@ "use strict"; | ||
__exportStar(require("./bloc-builder"), exports); | ||
var bloc_root_1 = require("./bloc-root"); | ||
Object.defineProperty(exports, "BlocRoot", { enumerable: true, get: function () { return bloc_root_1.BlocRoot; } }); | ||
__exportStar(require("./hooks"), exports); | ||
__exportStar(require("./registry"), exports); | ||
__exportStar(require("./with-blocs"), exports); | ||
var bloc_root_1 = require("./bloc-root"); | ||
Object.defineProperty(exports, "BlocRegistry", { enumerable: true, get: function () { return bloc_root_1.BlocRegistry; } }); | ||
Object.defineProperty(exports, "blocGetter", { enumerable: true, get: function () { return bloc_root_1.blocGetter; } }); | ||
Object.defineProperty(exports, "BlocRoot", { enumerable: true, get: function () { return bloc_root_1.BlocRoot; } }); | ||
//# sourceMappingURL=react-bloc.js.map |
{ | ||
"name": "@bloc-js/react-bloc", | ||
"version": "3.2.1", | ||
"version": "3.2.2", | ||
"description": "React components for implementing the BLoC pattern.", | ||
@@ -50,3 +50,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "5de9eefb44ae6a3051f150c75ad8601487a4c120" | ||
"gitHead": "b75b079923a3cf8b33ea55052a28dbe87b3b6436" | ||
} |
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
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
42270
57
663