@swear-js/react
Advanced tools
Comparing version 2.0.1 to 2.0.2
import { SwearId } from '@swear-js/core'; | ||
import { SwearActionType, SwearType } from './types'; | ||
export declare const createSwear: <T>(swearId: SwearId, defaultValue: T, actions: Record<string, SwearActionType<T>>) => SwearType<T>; | ||
import { SwearMutateType, SwearType } from './types'; | ||
export declare const createSwear: <T, Y>(swearId: SwearId, defaultValue: T, actions: (mutate: SwearMutateType<T>) => Y) => SwearType<T, Y>; |
export declare type SwearMutateType<T> = ((payload: T) => void) | (() => void); | ||
export declare type SwearReducerType<T> = ((payload: T) => void) | (() => void); | ||
export declare type SwearActionType<T> = (mutate: (value: SwearMutateType<T>) => void) => SwearReducerType<T>; | ||
export declare type SwearType<T> = [ | ||
export declare type SwearType<T, Y> = [ | ||
name: string, | ||
defaultValue: T, | ||
actions: Record<string, SwearActionType<T>> | ||
actions: ((mutate: SwearMutateType<T>) => Y) | ||
]; | ||
export declare type SwearReturnType<T, Y> = [value: T, actions: Record<string, Y>]; | ||
export declare type SwearDefaultActions<T> = { | ||
set: (payload: T) => void; | ||
reset: () => void; | ||
}; | ||
export declare type SwearReturnType<T, Y> = [ | ||
state: T, | ||
actions: { | ||
set: (payload: T) => void; | ||
reset: () => void; | ||
} & Y | ||
]; |
import React from 'react'; | ||
import { SwearType } from './types'; | ||
import { SwearReturnType, SwearType } from './types'; | ||
export declare const swearContext: React.Context<import("@swear-js/core").SwearStoreReturnType>; | ||
export declare const useSwear: <T>([swearId, defaultState, actions]: SwearType<T>) => readonly [T, { | ||
set: (payload: T) => void; | ||
reset: () => void; | ||
_tag: string; | ||
}]; | ||
export declare const useSwear: <T, Y>([swearId, defaultState, actions]: SwearType<T, Y>) => SwearReturnType<T, Y>; |
@@ -20,3 +20,2 @@ "use strict"; | ||
var core_1 = require("@swear-js/core"); | ||
var default_actions_1 = require("./default-actions"); | ||
exports.swearContext = react_1.default.createContext((0, core_1.createStore)()); | ||
@@ -38,14 +37,10 @@ var useSwear = function (_a) { | ||
}, []); | ||
var actionsWrapped = Object.entries(actions).reduce(function (acc, _a) { | ||
var _b; | ||
var actionType = _a[0], reducer = _a[1]; | ||
return (__assign(__assign({}, acc), (_b = {}, _b[actionType] = reducer(function (payload) { return (store === null || store === void 0 ? void 0 : store.setSwearValue(swearId, actionType, payload)); }), _b))); | ||
}, { | ||
set: (0, default_actions_1.set)(function (payload) { return (store === null || store === void 0 ? void 0 : store.setSwearValue(swearId, 'set', payload)); }), | ||
reset: (0, default_actions_1.reset)(defaultState)(function () { return (store === null || store === void 0 ? void 0 : store.setSwearValue(swearId, 'reset', defaultState)); }), | ||
_tag: 'actions', | ||
}); | ||
return [swearValue, actionsWrapped]; | ||
var defaultActions = function (mutate) { return ({ | ||
set: function (payload) { return (mutate(payload)); }, | ||
reset: function () { return mutate(defaultState); }, | ||
}); }; | ||
var mutator = function (payload) { return (store === null || store === void 0 ? void 0 : store.setSwearValue(swearId, 'someAction', payload)); }; | ||
return [swearValue, __assign(__assign({}, defaultActions(mutator)), actions(mutator))]; | ||
}; | ||
exports.useSwear = useSwear; | ||
//# sourceMappingURL=useSwear.js.map |
{ | ||
"name": "@swear-js/react", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "React support for swear-js", | ||
@@ -50,3 +50,3 @@ "repository": { | ||
}, | ||
"gitHead": "c092d32bf14e570b5ad023ce19a153b907ee0809" | ||
"gitHead": "63420ec4fda43dbe2e2aa2000a17a2391bc5f253" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
9443
14
92