Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@swear-js/react

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swear-js/react - npm Package Compare versions

Comparing version 2.2.0 to 3.0.0

2

lib/index.d.ts

@@ -1,5 +0,3 @@

export * from './types';
export * from './createSwear';
export * from './swearContext';
export * from './useSwear';
export * from './useSwearState';

@@ -13,4 +13,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./types"), exports);
__exportStar(require("./createSwear"), exports);
__exportStar(require("./swearContext"), exports);

@@ -17,0 +15,0 @@ __exportStar(require("./useSwear"), exports);

11

lib/swearContext.d.ts
import React from 'react';
export declare const swearContext: React.Context<import("@swear-js/core").SwearStoreReturnType>;
export declare const swearContext: React.Context<{
getStore: () => import("@swear-js/core").SwearStoreType<any>;
subscribe: <T, Y>(swear: import("@swear-js/core").SwearType<T, Y>, onUpdate: import("@swear-js/core").SwearSubscriberOnUpdate<T>) => void;
unsubscribe: <T_1, Y_1>(swear: import("@swear-js/core").SwearType<T_1, Y_1>) => void;
getSwearState: <T_2, Y_2>(swear: import("@swear-js/core").SwearType<T_2, Y_2>) => T_2;
getSwearActions: <T_3, Y_3>(swear: import("@swear-js/core").SwearType<T_3, Y_3>) => {
set: (payload: T_3 | ((prev: T_3) => T_3)) => void;
reset: () => void;
} & Y_3;
}>;

@@ -1,7 +0,1 @@

export declare type SwearMutateType<T> = ((payload: T | ((prev: T) => T), tag?: string) => void) | (() => void);
export declare type SwearType<T, Y> = [
name: string,
defaultValue: T,
actions: ((mutate: SwearMutateType<T>) => Y)
];
export declare type SwearDefaultActions<T> = {

@@ -8,0 +2,0 @@ set: (payload: T | ((prev: T) => T)) => void;

@@ -1,2 +0,3 @@

import { SwearReturnType, SwearType } from './types';
export declare const useSwear: <T, Y>([swearId, defaultState, actions]: SwearType<T, Y>) => SwearReturnType<T, Y>;
import { SwearType } from '@swear-js/core';
import { SwearReturnType } from './types';
export declare const useSwear: <T, Y>(swear: SwearType<T, Y>) => SwearReturnType<T, Y>;
"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) {

@@ -36,22 +25,16 @@ if (k2 === undefined) k2 = k;

var swearContext_1 = require("./swearContext");
var defaultActions_1 = require("./defaultActions");
var useSwear = function (_a) {
var _b;
var swearId = _a[0], defaultState = _a[1], actions = _a[2];
var useSwear = function (swear) {
var _a;
var store = react_1.default.useContext(swearContext_1.swearContext);
var _c = react_1.default.useState((_b = store.getSwearValue(swearId)) !== null && _b !== void 0 ? _b : defaultState), swearValue = _c[0], setSwearValue = _c[1];
var defaultState = swear[1];
var _b = react_1.default.useState((_a = store === null || store === void 0 ? void 0 : store.getSwearState(swear)) !== null && _a !== void 0 ? _a : defaultState), swearValue = _b[0], setSwearValue = _b[1];
(0, react_1.useEffect)(function () {
store === null || store === void 0 ? void 0 : store.subscribe({
swearId: swearId,
defaultState: defaultState,
onUpdate: function (newValue) {
setSwearValue(newValue);
},
store === null || store === void 0 ? void 0 : store.subscribe(swear, function (newValue) {
setSwearValue(newValue);
});
return function () { return store === null || store === void 0 ? void 0 : store.unsubscribe(swearId); };
return function () { return store === null || store === void 0 ? void 0 : store.unsubscribe(swear); };
}, []);
var mutator = function (payload, tag) { return store === null || store === void 0 ? void 0 : store.setSwearValue(swearId, tag !== null && tag !== void 0 ? tag : null, payload instanceof Function ? payload(swearValue) : payload); };
return [swearValue, __assign(__assign({}, (0, defaultActions_1.defaultActions)(defaultState, swearValue)(mutator)), actions(mutator))];
return [swearValue, store === null || store === void 0 ? void 0 : store.getSwearActions(swear)];
};
exports.useSwear = useSwear;
//# sourceMappingURL=useSwear.js.map
"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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSwearState = void 0;
var react_1 = require("react");
var core_1 = require("@swear-js/core");
var swearContext_1 = require("./swearContext");
var defaultActions_1 = require("./defaultActions");
var useSwearState = function (swearId, defaultState) {
var _a;
var store = (0, react_1.useContext)(swearContext_1.swearContext);
var _b = (0, react_1.useState)((_a = store.getSwearValue(swearId)) !== null && _a !== void 0 ? _a : defaultState), swearValue = _b[0], setSwearValue = _b[1];
var swear = (0, core_1.createSwear)(swearId, defaultState, function () { });
var _b = (0, react_1.useState)((_a = store === null || store === void 0 ? void 0 : store.getSwearState(swear)) !== null && _a !== void 0 ? _a : defaultState), swearValue = _b[0], setSwearValue = _b[1];
(0, react_1.useEffect)(function () {
store === null || store === void 0 ? void 0 : store.subscribe({
swearId: swearId,
defaultState: defaultState,
onUpdate: function (newValue) {
setSwearValue(newValue);
},
store === null || store === void 0 ? void 0 : store.subscribe(swear, function (newValue) {
setSwearValue(newValue);
});
return function () { return store === null || store === void 0 ? void 0 : store.unsubscribe(swearId); };
return function () { return store === null || store === void 0 ? void 0 : store.unsubscribe(swear); };
}, []);
var mutator = function (payload, tag) { return store === null || store === void 0 ? void 0 : store.setSwearValue(swearId, tag !== null && tag !== void 0 ? tag : null, payload instanceof Function ? payload(swearValue) : payload); };
return [swearValue, __assign({}, (0, defaultActions_1.defaultActions)(defaultState, swearValue)(mutator))];
return [swearValue, store === null || store === void 0 ? void 0 : store.getSwearActions(swear)];
};
exports.useSwearState = useSwearState;
//# sourceMappingURL=useSwearState.js.map
{
"name": "@swear-js/react",
"version": "2.2.0",
"version": "3.0.0",
"description": "React support for swear-js",

@@ -31,3 +31,3 @@ "repository": {

"dependencies": {
"@swear-js/core": "^2.1.0",
"@swear-js/core": "^3.0.0",
"@types/node": "^17.0.24",

@@ -51,3 +51,3 @@ "@types/react": "^18.0.5",

},
"gitHead": "0fb07a3e62e2ed3ef841d132843beeb148c59d2d"
"gitHead": "51c80a56e5a450c35285aa94a74bc5731dba2fa4"
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc