New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

informed

Package Overview
Dependencies
Maintainers
2
Versions
404
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

informed - npm Package Compare versions

Comparing version 4.59.1 to 4.60.0

50

dist/cjs/hooks/useArrayField.js

@@ -39,2 +39,5 @@ 'use strict';

// For knowing if we are performing reset
var resetRef = React.useRef(false);
// Map will store all fields by name

@@ -143,17 +146,16 @@ // Key => name

// First wipe the existing state
// Array fields are unique.. because reset will create new keys everything below gets wiped
// So, we can start by simply wiping out the state below here ( same thing we do at form level reset )
// ^^ By this I mean in form level reset we first wipe the form state :) so we can do same thing here!
// Array fields are unique.. because reset will create new keys every field will get unmounted
// So, we can start by simply wiping out the keys below here ( same thing we do at form level reset )
// this will result in all fields performing their cleanup rutines
logger("------------ ".concat(name, " Array Field Reset Start ------------"));
// Performing reset so we set the flag
resetRef.current = true;
// Remove array field
formController.remove(name);
// When resetting we reset to the users initial value not the one tracked by this hook
// Build new initial values
var initVals = initialValueRef.current || formController.getInitialValue(name) || defaultValueRef.current || [];
// Set our initial values back to what the user set at beginning
setInitialValues(initVals);
// Build a new set of keys because everything is new !!!
var resetKeys = initVals ? initVals.map(function () {
return utils.uuidv4();
}) : [];
// Finally set that shit !
setKeys(resetKeys);
// Clear out keys ( we wait until all fields have deregistered before resetting )
setKeys([]);
};

@@ -229,5 +231,25 @@ var clear = function clear() {

},
deregister: function deregister(n, m) {
deregister: function deregister(n) {
formController.deregister(n);
// Remove from our map
fieldsMap["delete"](n);
formController.deregister(n, m);
// On last deregister we finally complete
// console.log(`${name}-WTF1`, fieldsMap.size);
// console.log(`${name}-WTF2`, resetRef.current);
// NOTE: I originally tried to put the below logic inside of remove
// However this cuases issues because deregister is called with the correct name where remove may have old name
// Example [ 0, 1, 2 ] if we remove 1 then 2 moves to 1s place
if (!fieldsMap.size && resetRef.current) {
// V important we flag that we are done performing reset as all fields have deregistered
resetRef.current = false;
// For debug logging we show when complete
logger("------------ ".concat(name, " Array Field Reset End ------------"));
var initVals = getInitialValues();
// Build a new set of keys because everything is new !!!
var resetKeys = initVals ? initVals.map(function () {
return utils.uuidv4();
}) : [];
// Finally set that shit !
setKeys(resetKeys);
}
},

@@ -252,3 +274,3 @@ getInitialValue: function getInitialValue(fieldName) {

var v = ObjectMap.ObjectMap.get(getInitialValues(), path);
logger("Resetting ".concat(path, " to ").concat(v));
logger("Getting initial value for ".concat(path, " which is ").concat(v));
return v;

@@ -255,0 +277,0 @@ }

@@ -348,6 +348,2 @@ 'use strict';

useFieldSubscription.useFieldSubscription('field-value', validateWhen, function (target) {
logger("revalidating for ".concat(metaRef.current.name, " because of ").concat(target));
formController.validateField(metaRef.current.name);
});
useFieldSubscription.useFieldSubscription('field-value', [name], function (target) {

@@ -359,2 +355,6 @@ if (onValueChange) {

);
useFieldSubscription.useFieldSubscription('field-value', validateWhen, function (target) {
logger("revalidating for ".concat(metaRef.current.name, " because of ").concat(target));
formController.validateField(metaRef.current.name);
});
useUpdateEffect.useUpdateEffect(function () {

@@ -361,0 +361,0 @@ logger("revalidating for ".concat(metaRef.current.name, " because of deps change"));

@@ -76,2 +76,5 @@ 'use strict';

formController.emitter.on(event, listener);
if (scopedFields.length) {
debug("Adding subscription on event ".concat(event, ", subscribing to events from ").concat(scopedFields));
}

@@ -82,2 +85,5 @@ // When name changes we always force an update!

return function () {
if (scopedFields.length) {
debug("Removing subscription on event ".concat(event, ", un-subscribing to events from ").concat(scopedFields));
}
formController.emitter.removeListener(event, listener);

@@ -84,0 +90,0 @@ };

import { slicedToArray as _slicedToArray, objectSpread2 as _objectSpread2, toConsumableArray as _toConsumableArray } from '../_virtual/_rollupPluginBabelHelpers.js';
import React, { useContext, useState, useRef, useEffect, useMemo } from 'react';
import React, { useContext, useRef, useState, useEffect, useMemo } from 'react';
import { useStateWithGetter } from './useStateWithGetter.js';

@@ -31,2 +31,5 @@ import { Debug } from '../debug.js';

// For knowing if we are performing reset
var resetRef = useRef(false);
// Map will store all fields by name

@@ -135,17 +138,16 @@ // Key => name

// First wipe the existing state
// Array fields are unique.. because reset will create new keys everything below gets wiped
// So, we can start by simply wiping out the state below here ( same thing we do at form level reset )
// ^^ By this I mean in form level reset we first wipe the form state :) so we can do same thing here!
// Array fields are unique.. because reset will create new keys every field will get unmounted
// So, we can start by simply wiping out the keys below here ( same thing we do at form level reset )
// this will result in all fields performing their cleanup rutines
logger("------------ ".concat(name, " Array Field Reset Start ------------"));
// Performing reset so we set the flag
resetRef.current = true;
// Remove array field
formController.remove(name);
// When resetting we reset to the users initial value not the one tracked by this hook
// Build new initial values
var initVals = initialValueRef.current || formController.getInitialValue(name) || defaultValueRef.current || [];
// Set our initial values back to what the user set at beginning
setInitialValues(initVals);
// Build a new set of keys because everything is new !!!
var resetKeys = initVals ? initVals.map(function () {
return uuidv4();
}) : [];
// Finally set that shit !
setKeys(resetKeys);
// Clear out keys ( we wait until all fields have deregistered before resetting )
setKeys([]);
};

@@ -221,5 +223,25 @@ var clear = function clear() {

},
deregister: function deregister(n, m) {
deregister: function deregister(n) {
formController.deregister(n);
// Remove from our map
fieldsMap["delete"](n);
formController.deregister(n, m);
// On last deregister we finally complete
// console.log(`${name}-WTF1`, fieldsMap.size);
// console.log(`${name}-WTF2`, resetRef.current);
// NOTE: I originally tried to put the below logic inside of remove
// However this cuases issues because deregister is called with the correct name where remove may have old name
// Example [ 0, 1, 2 ] if we remove 1 then 2 moves to 1s place
if (!fieldsMap.size && resetRef.current) {
// V important we flag that we are done performing reset as all fields have deregistered
resetRef.current = false;
// For debug logging we show when complete
logger("------------ ".concat(name, " Array Field Reset End ------------"));
var initVals = getInitialValues();
// Build a new set of keys because everything is new !!!
var resetKeys = initVals ? initVals.map(function () {
return uuidv4();
}) : [];
// Finally set that shit !
setKeys(resetKeys);
}
},

@@ -244,3 +266,3 @@ getInitialValue: function getInitialValue(fieldName) {

var v = ObjectMap.get(getInitialValues(), path);
logger("Resetting ".concat(path, " to ").concat(v));
logger("Getting initial value for ".concat(path, " which is ").concat(v));
return v;

@@ -247,0 +269,0 @@ }

@@ -340,6 +340,2 @@ import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, toConsumableArray as _toConsumableArray, objectSpread2 as _objectSpread2 } from '../_virtual/_rollupPluginBabelHelpers.js';

useFieldSubscription('field-value', validateWhen, function (target) {
logger("revalidating for ".concat(metaRef.current.name, " because of ").concat(target));
formController.validateField(metaRef.current.name);
});
useFieldSubscription('field-value', [name], function (target) {

@@ -351,2 +347,6 @@ if (onValueChange) {

);
useFieldSubscription('field-value', validateWhen, function (target) {
logger("revalidating for ".concat(metaRef.current.name, " because of ").concat(target));
formController.validateField(metaRef.current.name);
});
useUpdateEffect(function () {

@@ -353,0 +353,0 @@ logger("revalidating for ".concat(metaRef.current.name, " because of deps change"));

@@ -72,2 +72,5 @@ import { toConsumableArray as _toConsumableArray } from '../_virtual/_rollupPluginBabelHelpers.js';

formController.emitter.on(event, listener);
if (scopedFields.length) {
debug("Adding subscription on event ".concat(event, ", subscribing to events from ").concat(scopedFields));
}

@@ -78,2 +81,5 @@ // When name changes we always force an update!

return function () {
if (scopedFields.length) {
debug("Removing subscription on event ".concat(event, ", un-subscribing to events from ").concat(scopedFields));
}
formController.emitter.removeListener(event, listener);

@@ -80,0 +86,0 @@ };

@@ -139,3 +139,3 @@ import React from 'react';

name: string;
}
};

@@ -407,3 +407,3 @@ export type ArrayFieldApi = {

export function useArrayField(params: {
export function useArrayField(params: {
name: string;

@@ -434,4 +434,4 @@ initialValue: any;

/** Json Schema */
schema: any,
onlyValidateSchema: boolean
schema: any;
onlyValidateSchema?: boolean;
}): JSX.Element[];

@@ -438,0 +438,0 @@

{
"name": "informed",
"version": "4.59.1",
"version": "4.60.0",
"description": "A lightweight framework and utility for building powerful forms in React applications",

@@ -5,0 +5,0 @@ "type": "module",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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