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

@superstate/core

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@superstate/core - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

2

core.js

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

function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},t.apply(this,arguments)}var e=function t(e,n){if(e===n)return!0;if(e&&n&&"object"==typeof e&&"object"==typeof n){if(e.constructor!==n.constructor)return!1;var r,o,i;if(Array.isArray(e)){if((r=e.length)!=n.length)return!1;for(o=r;0!=o--;)if(!t(e[o],n[o]))return!1;return!0}if(e.constructor===RegExp)return e.source===n.source&&e.flags===n.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===n.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===n.toString();if((r=(i=Object.keys(e)).length)!==Object.keys(n).length)return!1;for(o=r;0!=o--;)if(!Object.prototype.hasOwnProperty.call(n,i[o]))return!1;for(o=r;0!=o--;){var u=i[o];if(!t(e[u],n[u]))return!1}return!0}return e!=e&&n!=n};function n(t){if(void 0!==t)return t instanceof Map?new Map(t):t instanceof Set?new Set(t):JSON.parse(JSON.stringify(t))}exports.superstate=function(r){var o=r,i=void 0,u=[],c=[],f=[],a={draft:l,set:p,publish:v,discard:y},s=t({},a,{now:function(){return o},subscribe:function(t,e){if("draft"===e)return function(t){var e=c.length;return c.push(t),function(){return c=[].concat(c.slice(0,e),c.slice(e+1,c.length))}}(t);var n=u.length;return u.push(t),function(){return u=[].concat(u.slice(0,n),u.slice(n+1,u.length))}},extend:function(e){return t({},s,function(e){return Object.keys(e).reduce(function(n,r){var o;return t({},n,((o={})[r]=function(){if(void 0!==e[r].apply(e,[d()].concat([].slice.call(arguments))))return a},o))},{})}(e))},use:function(t){return b({eventType:"init"},t),f=[].concat(f,t),s},unsubscribeAll:function(){u=[],c=[]}});function l(){return i}function p(t,r){var u=n(i||o);b({eventType:"before:set"});var c=i;return i="function"==typeof t?t(u):t,null!=r&&r.silent||e(c,i)||h(),b({eventType:"after:set"}),a}function v(t,n){if(void 0!==t||void 0!==i){b({eventType:"before:publish"});var r=o;t&&p(t,{silent:!0}),o=i,y(),null!=n&&n.silent||e(r,o)||(b({eventType:"before:broadcast:now"}),u.forEach(function(t){return t(o)}),b({eventType:"after:broadcast:now"})),b({eventType:"after:publish"})}}function y(){b({eventType:"before:discard"}),i=void 0,h(),b({eventType:"after:discard"})}function b(e,n){var r=e.eventType,o=n||f;o.length&&o.forEach(function(e){e(t({eventType:r},s))})}function d(){return{draft:l,set:p,publish:v,discard:y,now:n(o)}}function h(){b({eventType:"before:broadcast:draft"}),c.forEach(function(t){return t(i)}),b({eventType:"after:broadcast:draft"})}return s};
function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},e.apply(this,arguments)}var t=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var r,u,o;if(Array.isArray(t)){if((r=t.length)!=n.length)return!1;for(u=r;0!=u--;)if(!e(t[u],n[u]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((r=(o=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(u=r;0!=u--;)if(!Object.prototype.hasOwnProperty.call(n,o[u]))return!1;for(u=r;0!=u--;){var i=o[u];if(!e(t[i],n[i]))return!1}return!0}return t!=t&&n!=n};exports.superstate=function(n){var r=n,u=void 0,o=[],i=[],c=[],f={draft:function(){return u},sketch:function(e,n){var o,i=u,c=p(null!=(o=u)?o:r,e);return t(i,c)||(v({eventType:"before:sketch"}),u=c,v({eventType:"after:sketch"}),null!=n&&n.silent||h()),a},publish:function(e){if(void 0===u)return a;var n=u;return t(r,n)||(v({eventType:"before:publish"}),l(n),v({eventType:"after:publish"}),s(),null!=e&&e.silent||b()),a},discard:s},a=e({},f,{set:function(e,n){if(void 0===e&&void 0===u)return a;var o=r,i=p(r,e);return t(o,i)||(v({eventType:"before:set"}),l(i),v({eventType:"after:set"}),null!=n&&n.silent||b()),a},now:function(){return r},subscribe:function(e,t){if("draft"===t)return function(e){var t=i.length;return i.push(e),function(){return i=[].concat(i.slice(0,t),i.slice(t+1,i.length))}}(e);var n=o.length;return o.push(e),function(){return o=[].concat(o.slice(0,n),o.slice(n+1,o.length))}},extend:function(t){return e({},a,function(t){return Object.keys(t).reduce(function(n,r){var u;return e({},n,((u={})[r]=function(){if(void 0!==t[r].apply(t,[y()].concat([].slice.call(arguments))))return f},u))},{})}(t))},use:function(e){return v({eventType:"init"},e),c=[].concat(c,e),a},unsubscribeAll:function(){o=[],i=[]}});function s(e){return void 0===u||(v({eventType:"before:discard"}),u=void 0,v({eventType:"after:discard"}),null!=e&&e.silent||h()),a}function l(e){v({eventType:"before:change"}),r=e,v({eventType:"after:change"})}function p(e,t){var n=function(e){if(void 0!==e)return e instanceof Map?new Map(e):e instanceof Set?new Set(e):JSON.parse(JSON.stringify(e))}(e);return function(e){return"function"==typeof e}(t)?t(n):t}function v(t,n){var r=t.eventType,u=n||c;u.length&&u.forEach(function(t){t(e({eventType:r},a))})}function y(){return a}function b(){v({eventType:"before:broadcast:now"}),o.forEach(function(e){return e(r)}),v({eventType:"after:broadcast:now"})}function h(){v({eventType:"before:broadcast:draft"}),i.forEach(function(e){return e(u)}),v({eventType:"after:broadcast:draft"})}return a};

@@ -10,6 +10,12 @@ /**

/**
* @returns The most accurate value of your state. The one your clients must trust the most.
* @returns The current value of the state.
*/
now: () => S;
/**
* Mutates the value of `now`. If the input is `undefined`, it uses the `draft` value instead.
*
* It won't broadcast any changes if the previous `now` would be equal the new `now`.
*/
set: ISetFn<S>;
/**
* Starts monitoring changes to the state.

@@ -49,25 +55,23 @@ *

/**
* Overrides the value of `now` with the value of `draft`.
*
* If `draft` is `undefined`, nothing will happen.
*
* If `draft` is equals to `now`, nothing will happen either.
*/
publish: () => ISuperState<S>;
/**
* Discards the draft, setting its value to `undefined`.
* Upon calling this function, a draft broadcast will occur.
*/
discard: IDiscardFn;
discard: IDiscardFn<S>;
/**
* Publishes the value passed in the input or the `draft`, if the input is `undefined`.
* Assigns the value passed via `input` to `draft`.
*
* It won't broadcast any changes if the previous `now` would be equal the new `now`.
*/
publish: IPublishFn<S>;
/**
* Sets the value passed through `input` to the draft.
*
* This function won't broadcast a draft change if the previous value is equal to the new value.
*
* @param input It can be a raw value or a function whose first and sole argument is the value of the previous `draft`. In case there is no previous draft, the first argument will be the previous value of `now`.
* @param options.silent (default: `false`) Whether to broadcast the change.
*/
set: ISetFn<S>;
sketch: ISketchFn<S>;
}
export declare type IExtensionPropsBag<S> = ISuperStateDraftMethods<S> & {
now: S;
};
export declare type IExtensionPropsBag<S> = ISuperState<S>;
/**

@@ -79,4 +83,4 @@ * The type of the draft.

export declare type IDraft<S> = S | undefined;
declare type ISetInput<S> = ((prev: S) => S) | S;
declare type ISetOptions = {
declare type IMutateInput<S> = ((prev: S) => S) | S;
declare type IMutateOptions = {
/**

@@ -101,5 +105,5 @@ * Whether to broadcast the change or not.

declare type IUnsubscribe = () => void;
declare type ISetFn<S> = (input: ISetInput<S>, options?: ISetOptions) => ISuperStateDraftMethods<S>;
declare type IPublishFn<S> = (input?: ISetInput<S>, options?: ISetOptions) => void;
declare type IDiscardFn = () => void;
declare type ISketchFn<S> = (input: IMutateInput<S>, options?: IMutateOptions) => ISuperState<S>;
declare type ISetFn<S> = (input: IMutateInput<S>, options?: IMutateOptions) => ISuperState<S>;
declare type IDiscardFn<S> = () => ISuperState<S>;
declare type IDraftFn<S> = () => IDraft<S>;

@@ -112,3 +116,3 @@ declare type IUseFn<S> = (middlewares: IMiddleware<S>[]) => ISuperState<S>;

declare type IMiddleware<S> = (input: IMiddlewareInput<S>) => void;
declare type IMiddlewareEventType = 'init' | 'before:publish' | 'after:publish' | 'before:set' | 'after:set' | 'before:discard' | 'after:discard' | 'before:broadcast:now' | 'after:broadcast:now' | 'before:broadcast:draft' | 'after:broadcast:draft';
declare type IMiddlewareEventType = 'init' | 'before:set' | 'after:set' | 'before:sketch' | 'after:sketch' | 'before:publish' | 'after:publish' | 'before:change' | 'after:change' | 'before:discard' | 'after:discard' | 'before:broadcast:now' | 'after:broadcast:now' | 'before:broadcast:draft' | 'after:broadcast:draft';
export {};
{
"name": "@superstate/core",
"version": "0.0.11",
"version": "0.0.12",
"description": "The essential package for superstate, the state management library.",

@@ -5,0 +5,0 @@ "main": "./core.js",

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