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

dom-augmentor

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-augmentor - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

20

cjs/index.js

@@ -10,2 +10,3 @@ 'use strict';

augmentor: $augmentor,
useEffect: $useEffect,
dropEffect

@@ -41,10 +42,16 @@ } = require('augmentor');

}
return element;
};
let effect = false;
const augmentor = fn => {
const hook = $augmentor(fn);
const disconnect = dropEffect.bind(null, hook);
let handler = null;
return function () {
return observer(hook.apply(this, arguments), disconnect);
effect = false;
const node = hook.apply(this, arguments);
if (effect) {
effect = false;
observer(node, handler || (handler = dropEffect.bind(null, hook)));
}
return node;
};

@@ -57,3 +64,2 @@ };

exports.useState = m.useState;
exports.useEffect = m.useEffect;
exports.useLayoutEffect = m.useLayoutEffect;

@@ -67,1 +73,7 @@ exports.useContext = m.useContext;

})(require('augmentor'));
function useEffect() {
effect = true;
return $useEffect.apply(null, arguments);
}
exports.useEffect = useEffect

@@ -9,2 +9,3 @@ /*! (c) Andrea Giammarchi - ISC */

augmentor as $augmentor,
useEffect as $useEffect,
dropEffect

@@ -40,10 +41,16 @@ } from 'augmentor';

}
return element;
};
let effect = false;
export const augmentor = fn => {
const hook = $augmentor(fn);
const disconnect = dropEffect.bind(null, hook);
let handler = null;
return function () {
return observer(hook.apply(this, arguments), disconnect);
effect = false;
const node = hook.apply(this, arguments);
if (effect) {
effect = false;
observer(node, handler || (handler = dropEffect.bind(null, hook)));
}
return node;
};

@@ -55,3 +62,3 @@ };

useState,
useEffect, useLayoutEffect,
useLayoutEffect,
useContext, createContext,

@@ -63,1 +70,6 @@ useReducer,

} from 'augmentor';
export function useEffect() {
effect = true;
return $useEffect.apply(null, arguments);
}

96

index.js

@@ -154,7 +154,2 @@ var augmentor = (function (exports) {

var curr = null;
var invoke = function invoke(fn) {
fn();
};
var augmentor = function augmentor(fn) {

@@ -165,3 +160,2 @@ var stack = [];

var after = [];
var i = 0;
curr = {

@@ -171,7 +165,3 @@ hook: hook,

stack: stack,
get index() {
return i++;
},
i: 0,
after: after

@@ -184,3 +174,6 @@ };

curr = prev;
after.forEach(invoke);
for (var i = 0, length = after.length; i < length; i++) {
after[i]();
}
}

@@ -254,15 +247,15 @@ };

var useState = function useState(value, options) {
var _current = current(),
hook = _current.hook,
args = _current.args,
stack = _current.stack,
index = _current.index;
var state = current();
var i = state.i++;
var hook = state.hook,
args = state.args,
stack = state.stack;
if (stack.length <= index) {
stack[index] = isFunction(value) ? value() : value;
if (stack.length <= i) {
stack[i] = isFunction(value) ? value() : value;
if (!updates.has(hook)) updates.set(hook, options && options.sync ? update : reraf());
}
return [stack[index], function (value) {
stack[index] = isFunction(value) ? value(stack[index]) : value;
return [stack[i], function (value) {
stack[i] = isFunction(value) ? value(stack[i]) : value;
updates.get(hook)(hook, null, args);

@@ -275,3 +268,3 @@ }];

var invoke$1 = function invoke(_ref) {
var invoke = function invoke(_ref) {
var hook = _ref.hook,

@@ -307,3 +300,3 @@ args = _ref.args;

this.value = value;
hooks.get(this).forEach(invoke$1);
hooks.get(this).forEach(invoke);
}

@@ -324,10 +317,10 @@ }

return function (effect, guards) {
var _current = current(),
hook = _current.hook,
stack = _current.stack,
index = _current.index,
after = _current.after;
var state = current();
var i = state.i++;
var hook = state.hook,
stack = state.stack,
after = state.after;
if (index < stack.length) {
var info = stack[index];
if (i < stack.length) {
var info = stack[i];
var clean = info.clean,

@@ -363,3 +356,3 @@ update = info.update,

};
stack[index] = _info;
stack[i] = _info;
details.stack.push(_info);

@@ -393,11 +386,10 @@

var useMemo = function useMemo(memo, guards) {
var _current = current(),
stack = _current.stack,
index = _current.index;
if (!guards || stack.length <= index || guards.some(different, stack[index].values)) stack[index] = {
var state = current();
var i = state.i++;
var stack = state.stack;
if (!guards || stack.length <= i || guards.some(different, stack[i].values)) stack[i] = {
current: memo(),
values: guards
};
return stack[index].current;
return stack[i].current;
};

@@ -422,7 +414,6 @@ var useCallback = function useCallback(fn, guards) {

var useRef = function useRef(value) {
var _current = current(),
stack = _current.stack,
index = _current.index;
return index < stack.length ? stack[index] : stack[index] = {
var state = current();
var i = state.i++;
var stack = state.stack;
return i < stack.length ? stack[i] : stack[i] = {
current: value

@@ -464,13 +455,24 @@ };

}
return element;
};
var effect = false;
var augmentor$1 = function augmentor$1(fn) {
var hook = augmentor(fn);
var disconnect = dropEffect.bind(null, hook);
var handler = null;
return function () {
return observer(hook.apply(this, arguments), disconnect);
effect = false;
var node = hook.apply(this, arguments);
if (effect) {
effect = false;
observer(node, handler || (handler = dropEffect.bind(null, hook)));
}
return node;
};
};
function useEffect$1() {
effect = true;
return useEffect.apply(null, arguments);
}

@@ -482,3 +484,3 @@ exports.augmentor = augmentor$1;

exports.useContext = useContext;
exports.useEffect = useEffect;
exports.useEffect = useEffect$1;
exports.useLayoutEffect = useLayoutEffect;

@@ -485,0 +487,0 @@ exports.useMemo = useMemo;

/*! (c) Andrea Giammarchi - ISC */
var augmentor=function(n){"use strict";var e={};e.CustomEvent="function"==typeof CustomEvent?CustomEvent:function(n){return e.prototype=new e("").constructor.prototype,e;function e(n,e){e||(e={});var t=document.createEvent("CustomEvent");return t.initCustomEvent(n,!!e.bubbles,!!e.cancelable,e.detail),t}}();var t=e.CustomEvent,r={};try{r.WeakSet=WeakSet}catch(n){!function(n){var e=new n,t=u.prototype;function u(t){e.set(this,new n),t&&t.forEach(this.add,this)}t.add=function(n){return e.get(this).set(n,1),this},t.delete=function(n){return e.get(this).delete(n)},t.has=function(n){return e.get(this).has(n)},r.WeakSet=u}(WeakMap)}var u=r.WeakSet;var o=null,a=function(n){n()},c=function(n){var e=[];return function t(){var r=o,u=[],c=0;o={hook:t,args:arguments,stack:e,get index(){return c++},after:u};try{return n.apply(null,arguments)}finally{o=r,u.forEach(a)}}},i=function(){return o};function s(n,e){return n!==this[e]}var f=function(n){return"function"==typeof n},l="function"==typeof cancelAnimationFrame,v=l?cancelAnimationFrame:clearTimeout,d=l?requestAnimationFrame:setTimeout;function h(n){var e,t,r,u,o;return c(),function(n,c,s){return r=n,u=c,o=s,t||(t=d(a)),--e<0&&i(!0),i};function a(){c(),r.apply(u,o||[])}function c(){e=n||1/0,t=l?0:null}function i(n){var e=!!t;return e&&(v(t),n&&a()),e}}var p=new WeakMap,m=function(n,e,t){n.apply(e,t)},g=function(n,e){var t=i(),r=t.hook,u=t.args,o=t.stack,a=t.index;return o.length<=a&&(o[a]=f(n)?n():n,p.has(r)||p.set(r,e&&e.sync?m:h())),[o[a],function(n){o[a]=f(n)?n(o[a]):n,p.get(r)(r,null,u)}]},k=new WeakMap,y=function(n){var e=n.hook,t=n.args;e.apply(null,t)};function E(n){this.value!==n&&(this.value=n,k.get(this).forEach(y))}function w(n){return n.hook===this.hook}var b=new WeakMap,W=function(){},C=function(n){return function(e,t){var r=i(),u=r.hook,o=r.stack,a=r.index,c=r.after;if(a<o.length){var f=o[a],l=f.clean,v=f.update,d=f.values;if(!t||t.some(s,d)){f.values=t,l&&(f.clean=null,l());var p=function(){f.clean=e()};n?c.push(p):v(p)}}else{b.has(u)||b.set(u,{stack:[],update:h()});var m=b.get(u),g={clean:null,stop:W,update:m.update,values:t};o[a]=g,m.stack.push(g);var k=function(){g.clean=e()};n?c.push(k):g.stop=m.update(k)}}},N=C(!1),x=C(!0),M=function(n,e){var t=i(),r=t.stack,u=t.index;return(!e||r.length<=u||e.some(s,r[u].values))&&(r[u]={current:n(),values:e}),r[u].current},S=function(n){var e=n.Event,t=n.WeakSet,r=!0,u=null;return function(n){return r&&(r=!r,u=new t,function(n){var r=new t,o=new t;try{new MutationObserver(s).observe(n,{subtree:!0,childList:!0})}catch(e){var a=0,c=[],i=function(n){c.push(n),clearTimeout(a),a=setTimeout(function(){s(c.splice(a=0,c.length))},0)};n.addEventListener("DOMNodeRemoved",function(n){i({addedNodes:[],removedNodes:[n.target]})},!0),n.addEventListener("DOMNodeInserted",function(n){i({addedNodes:[n.target],removedNodes:[]})},!0)}function s(n){for(var e,t=n.length,u=0;u<t;u++)f((e=n[u]).removedNodes,"disconnected",o,r),f(e.addedNodes,"connected",r,o)}function f(n,t,r,u){for(var o,a=new e(t),c=n.length,i=0;i<c;1===(o=n[i++]).nodeType&&l(o,a,t,r,u));}function l(n,e,t,r,o){u.has(n)&&!r.has(n)&&(o.delete(n),r.add(n),n.dispatchEvent(e));for(var a=n.children||[],c=a.length,i=0;i<c;l(a[i++],e,t,r,o));}}(n.ownerDocument)),u.add(n),n}}({Event:t,WeakSet:u});return n.augmentor=function(n){var e=c(n),t=function(n){b.has(n)&&b.get(n).stack.forEach(function(n){var e=n.clean;(0,n.stop)(),e&&(n.clean=null,e())})}.bind(null,e);return function(){return function n(e,t){var r=e.nodeType;if(r){var u=1===r?e:function(n){for(var e=n.childNodes,t=e.length,r=0;r<t;){var u=e[r++];if(1===u.nodeType)return u}throw"unobservable"}(e);S(u),u.addEventListener("disconnected",t,!1)}else{var o=e.valueOf();o!==e&&n(o,t)}return e}(e.apply(this,arguments),t)}},n.contextual=function(n){var e=null,t=c(function(){return n.apply(e,arguments)});return function(){return e=this,t.apply(this,arguments)}},n.createContext=function(n){var e={value:n,provide:E};return k.set(e,[]),e},n.useCallback=function(n,e){return M(function(){return n},e)},n.useContext=function(n){var e=i(),t=e.hook,r=e.args,u=k.get(n),o={hook:t,args:r};return u.some(w,o)||u.push(o),n.value},n.useEffect=N,n.useLayoutEffect=x,n.useMemo=M,n.useReducer=function(n,e,t,r){var u="function"==typeof t,o=g(u?t(e):e,u?r:t);return[o[0],function(e){o[1](n(o[0],e))}]},n.useRef=function(n){var e=i(),t=e.stack,r=e.index;return r<t.length?t[r]:t[r]={current:n}},n.useState=g,n}({});
var augmentor=function(n){"use strict";var e={};e.CustomEvent="function"==typeof CustomEvent?CustomEvent:function(n){return e.prototype=new e("").constructor.prototype,e;function e(n,e){e||(e={});var t=document.createEvent("CustomEvent");return t.initCustomEvent(n,!!e.bubbles,!!e.cancelable,e.detail),t}}();var t=e.CustomEvent,r={};try{r.WeakSet=WeakSet}catch(n){!function(n){var e=new n,t=u.prototype;function u(t){e.set(this,new n),t&&t.forEach(this.add,this)}t.add=function(n){return e.get(this).set(n,1),this},t.delete=function(n){return e.get(this).delete(n)},t.has=function(n){return e.get(this).has(n)},r.WeakSet=u}(WeakMap)}var u=r.WeakSet;var a=null,o=function(n){var e=[];return function t(){var r=a,u=[];a={hook:t,args:arguments,stack:e,i:0,after:u};try{return n.apply(null,arguments)}finally{a=r;for(var o=0,c=u.length;o<c;o++)u[o]()}}},c=function(){return a};function i(n,e){return n!==this[e]}var s=function(n){return"function"==typeof n},f="function"==typeof cancelAnimationFrame,l=f?cancelAnimationFrame:clearTimeout,v=f?requestAnimationFrame:setTimeout;function d(n){var e,t,r,u,a;return c(),function(n,c,s){return r=n,u=c,a=s,t||(t=v(o)),--e<0&&i(!0),i};function o(){c(),r.apply(u,a||[])}function c(){e=n||1/0,t=f?0:null}function i(n){var e=!!t;return e&&(l(t),n&&o()),e}}var h=new WeakMap,p=function(n,e,t){n.apply(e,t)},m=function(n,e){var t=c(),r=t.i++,u=t.hook,a=t.args,o=t.stack;return o.length<=r&&(o[r]=s(n)?n():n,h.has(u)||h.set(u,e&&e.sync?p:d())),[o[r],function(n){o[r]=s(n)?n(o[r]):n,h.get(u)(u,null,a)}]},g=new WeakMap,k=function(n){var e=n.hook,t=n.args;e.apply(null,t)};function y(n){this.value!==n&&(this.value=n,g.get(this).forEach(k))}function E(n){return n.hook===this.hook}var w=new WeakMap,b=function(){},W=function(n){return function(e,t){var r=c(),u=r.i++,a=r.hook,o=r.stack,s=r.after;if(u<o.length){var f=o[u],l=f.clean,v=f.update,h=f.values;if(!t||t.some(i,h)){f.values=t,l&&(f.clean=null,l());var p=function(){f.clean=e()};n?s.push(p):v(p)}}else{w.has(a)||w.set(a,{stack:[],update:d()});var m=w.get(a),g={clean:null,stop:b,update:m.update,values:t};o[u]=g,m.stack.push(g);var k=function(){g.clean=e()};n?s.push(k):g.stop=m.update(k)}}},C=W(!1),N=W(!0),M=function(n,e){var t=c(),r=t.i++,u=t.stack;return(!e||u.length<=r||e.some(i,u[r].values))&&(u[r]={current:n(),values:e}),u[r].current},S=function(n){var e=n.Event,t=n.WeakSet,r=!0,u=null;return function(n){return r&&(r=!r,u=new t,function(n){var r=new t,a=new t;try{new MutationObserver(s).observe(n,{subtree:!0,childList:!0})}catch(e){var o=0,c=[],i=function(n){c.push(n),clearTimeout(o),o=setTimeout(function(){s(c.splice(o=0,c.length))},0)};n.addEventListener("DOMNodeRemoved",function(n){i({addedNodes:[],removedNodes:[n.target]})},!0),n.addEventListener("DOMNodeInserted",function(n){i({addedNodes:[n.target],removedNodes:[]})},!0)}function s(n){for(var e,t=n.length,u=0;u<t;u++)f((e=n[u]).removedNodes,"disconnected",a,r),f(e.addedNodes,"connected",r,a)}function f(n,t,r,u){for(var a,o=new e(t),c=n.length,i=0;i<c;1===(a=n[i++]).nodeType&&l(a,o,t,r,u));}function l(n,e,t,r,a){u.has(n)&&!r.has(n)&&(a.delete(n),r.add(n),n.dispatchEvent(e));for(var o=n.children||[],c=o.length,i=0;i<c;l(o[i++],e,t,r,a));}}(n.ownerDocument)),u.add(n),n}}({Event:t,WeakSet:u}),T=!1;return n.augmentor=function(n){var e=o(n),t=null;return function(){T=!1;var n=e.apply(this,arguments);return T&&(T=!1,function n(e,t){var r=e.nodeType;if(r){var u=1===r?e:function(n){for(var e=n.childNodes,t=e.length,r=0;r<t;){var u=e[r++];if(1===u.nodeType)return u}throw"unobservable"}(e);S(u),u.addEventListener("disconnected",t,!1)}else{var a=e.valueOf();a!==e&&n(a,t)}}(n,t||(t=function(n){w.has(n)&&w.get(n).stack.forEach(function(n){var e=n.clean;(0,n.stop)(),e&&(n.clean=null,e())})}.bind(null,e)))),n}},n.contextual=function(n){var e=null,t=o(function(){return n.apply(e,arguments)});return function(){return e=this,t.apply(this,arguments)}},n.createContext=function(n){var e={value:n,provide:y};return g.set(e,[]),e},n.useCallback=function(n,e){return M(function(){return n},e)},n.useContext=function(n){var e=c(),t=e.hook,r=e.args,u=g.get(n),a={hook:t,args:r};return u.some(E,a)||u.push(a),n.value},n.useEffect=function(){return T=!0,C.apply(null,arguments)},n.useLayoutEffect=N,n.useMemo=M,n.useReducer=function(n,e,t,r){var u="function"==typeof t,a=m(u?t(e):e,u?r:t);return[a[0],function(e){a[1](n(a[0],e))}]},n.useRef=function(n){var e=c(),t=e.i++,r=e.stack;return t<r.length?r[t]:r[t]={current:n}},n.useState=m,n}({});
{
"name": "dom-augmentor",
"version": "1.3.0",
"version": "1.3.1",
"description": "DOM oriented useEffect hooks for the augmentor",

@@ -9,3 +9,3 @@ "main": "cjs/index.js",

"scripts": {
"build": "npm run rollup && npm run cjs && npm run min && npm run size",
"build": "npm run rollup && npm run cjs && npm run min && npm run test && npm run size",
"cjs": "ascjs esm cjs",

@@ -36,3 +36,3 @@ "coveralls": "cat ./coverage/lcov.info | coveralls",

"@ungap/weakset": "^0.1.5",
"augmentor": "^1.3.0",
"augmentor": "^1.3.1",
"disconnected": "^0.2.1"

@@ -49,3 +49,3 @@ },

"istanbul": "^0.4.5",
"rollup": "^1.27.2",
"rollup": "^1.27.3",
"rollup-plugin-babel": "^4.3.3",

@@ -52,0 +52,0 @@ "rollup-plugin-node-resolve": "^5.2.0",

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