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

json-react-layouts-data-loader

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-react-layouts-data-loader - npm Package Compare versions

Comparing version 2.3.0 to 3.0.0

27

dist/cjs/data-loading.test.js

@@ -6,2 +6,3 @@ "use strict";

var react_1 = tslib_1.__importDefault(require("react"));
var test_utils_1 = require("react-dom/test-utils");
var enzyme_adapter_react_16_1 = tslib_1.__importDefault(require("enzyme-adapter-react-16"));

@@ -106,3 +107,3 @@ var _1 = require(".");

it('component can provide additional arguments dynamically', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var resources, _a, middleware, createRegisterableComponentWithData, lengthCalculatorWithMultiplierDataDefinition, testComponentWithDataRegistration, layout, wrapper, component;
var resources, _a, middleware, createRegisterableComponentWithData, updateMultiplier, lengthCalculatorWithMultiplierDataDefinition, testComponentWithDataRegistration, layout, wrapper, component;
return tslib_1.__generator(this, function (_b) {

@@ -113,6 +114,11 @@ switch (_b.label) {

_a = _1.init(resources), middleware = _a.middleware, createRegisterableComponentWithData = _a.createRegisterableComponentWithData;
updateMultiplier = function () { };
lengthCalculatorWithMultiplierDataDefinition = {
getRuntimeParams: function () {
useRuntimeParams: function () {
var _a = react_1.default.useState(2), multiplier = _a[0], setMultiplier = _a[1];
react_1.default.useEffect(function () {
updateMultiplier = setMultiplier;
}, []);
return {
multiplier: 2,
multiplier: multiplier,
};

@@ -167,2 +173,17 @@ },

});
test_utils_1.act(function () {
updateMultiplier(3);
});
return [4, new Promise(function (resolve) { return setTimeout(resolve); })];
case 2:
_b.sent();
component = wrapper.update().find(TestComponentWithData);
expect(component.text()).toBe('Length: 9');
expect(component.props()).toMatchObject({
dataProps: {
data: {
dataDefinitionArgs: { dataArg: 'Foo', multiplier: 3 },
},
},
});
return [2];

@@ -169,0 +190,0 @@ }

2

dist/cjs/DataLoading.d.ts

@@ -8,3 +8,3 @@ import { LayoutApi } from 'json-react-layouts';

export interface DataDefinition<DataLoadArguments extends object, TData, Services extends object, AdditionalParams extends object = {}> {
getRuntimeParams?: (dataDefinitionArgs: DataLoadArguments, services: Services) => AdditionalParams;
useRuntimeParams?: (dataDefinitionArgs: DataLoadArguments, services: Services) => AdditionalParams;
loadData: LoadData<DataLoadArguments & AdditionalParams, TData, Services>;

@@ -11,0 +11,0 @@ }

@@ -29,5 +29,5 @@ "use strict";

if (dataDefinition) {
var dataDefinitionArgs = dataDefinition.getRuntimeParams
? tslib_1.__assign({}, componentProps.dataDefinitionArgs, dataDefinition.getRuntimeParams(componentProps.dataDefinitionArgs, services.services)) : componentProps.dataDefinitionArgs;
if (dataDefinition.getRuntimeParams) {
var dataDefinitionArgs = dataDefinition.useRuntimeParams
? tslib_1.__assign({}, componentProps.dataDefinitionArgs, dataDefinition.useRuntimeParams(componentProps.dataDefinitionArgs, services.services)) : componentProps.dataDefinitionArgs;
if (dataDefinition.useRuntimeParams) {
componentProps = tslib_1.__assign({}, componentProps, { dataDefinitionArgs: dataDefinitionArgs });

@@ -34,0 +34,0 @@ }

var _this = this;
import * as tslib_1 from "tslib";
import React from 'react';
import { act } from 'react-dom/test-utils';
import Adapter from 'enzyme-adapter-react-16';

@@ -103,3 +104,3 @@ import { init } from '.';

it('component can provide additional arguments dynamically', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var resources, _a, middleware, createRegisterableComponentWithData, lengthCalculatorWithMultiplierDataDefinition, testComponentWithDataRegistration, layout, wrapper, component;
var resources, _a, middleware, createRegisterableComponentWithData, updateMultiplier, lengthCalculatorWithMultiplierDataDefinition, testComponentWithDataRegistration, layout, wrapper, component;
return tslib_1.__generator(this, function (_b) {

@@ -110,6 +111,11 @@ switch (_b.label) {

_a = init(resources), middleware = _a.middleware, createRegisterableComponentWithData = _a.createRegisterableComponentWithData;
updateMultiplier = function () { };
lengthCalculatorWithMultiplierDataDefinition = {
getRuntimeParams: function () {
useRuntimeParams: function () {
var _a = React.useState(2), multiplier = _a[0], setMultiplier = _a[1];
React.useEffect(function () {
updateMultiplier = setMultiplier;
}, []);
return {
multiplier: 2,
multiplier: multiplier,
};

@@ -164,2 +170,17 @@ },

});
act(function () {
updateMultiplier(3);
});
return [4, new Promise(function (resolve) { return setTimeout(resolve); })];
case 2:
_b.sent();
component = wrapper.update().find(TestComponentWithData);
expect(component.text()).toBe('Length: 9');
expect(component.props()).toMatchObject({
dataProps: {
data: {
dataDefinitionArgs: { dataArg: 'Foo', multiplier: 3 },
},
},
});
return [2];

@@ -166,0 +187,0 @@ }

@@ -8,3 +8,3 @@ import { LayoutApi } from 'json-react-layouts';

export interface DataDefinition<DataLoadArguments extends object, TData, Services extends object, AdditionalParams extends object = {}> {
getRuntimeParams?: (dataDefinitionArgs: DataLoadArguments, services: Services) => AdditionalParams;
useRuntimeParams?: (dataDefinitionArgs: DataLoadArguments, services: Services) => AdditionalParams;
loadData: LoadData<DataLoadArguments & AdditionalParams, TData, Services>;

@@ -11,0 +11,0 @@ }

@@ -26,5 +26,5 @@ import * as tslib_1 from "tslib";

if (dataDefinition) {
var dataDefinitionArgs = dataDefinition.getRuntimeParams
? tslib_1.__assign({}, componentProps.dataDefinitionArgs, dataDefinition.getRuntimeParams(componentProps.dataDefinitionArgs, services.services)) : componentProps.dataDefinitionArgs;
if (dataDefinition.getRuntimeParams) {
var dataDefinitionArgs = dataDefinition.useRuntimeParams
? tslib_1.__assign({}, componentProps.dataDefinitionArgs, dataDefinition.useRuntimeParams(componentProps.dataDefinitionArgs, services.services)) : componentProps.dataDefinitionArgs;
if (dataDefinition.useRuntimeParams) {
componentProps = tslib_1.__assign({}, componentProps, { dataDefinitionArgs: dataDefinitionArgs });

@@ -31,0 +31,0 @@ }

{
"name": "json-react-layouts-data-loader",
"version": "2.3.0",
"version": "3.0.0",
"main": "dist/cjs/index.js",

@@ -29,4 +29,4 @@ "module": "dist/esm/index.js",

"@types/jest": "^24.0.18",
"@types/node": "^12.7.3",
"@types/react": "^16.9.2",
"@types/react-dom": "^16.9.0",
"@typescript-eslint/eslint-plugin": "^2.1.0",

@@ -42,9 +42,9 @@ "@typescript-eslint/parser": "^2.1.0",

"jest": "^24.9.0",
"json-react-layouts": "^2.0.1",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-ssr-data-loader": "^1.2.0",
"react-ssr-data-loader": "^1.3.0",
"ts-jest": "^24.0.2",
"tslib": "^1.10.0",
"typescript": "3.5.3",
"json-react-layouts": "^2.0.1"
"typescript": "3.5.3"
},

@@ -56,4 +56,4 @@ "dependencies": {

"json-react-layouts": "^2.0.1",
"react-ssr-data-loader": "^1.2.0"
"react-ssr-data-loader": "^1.3.0"
}
}

@@ -47,4 +47,6 @@ # JSON React layouts data loader

You can use the `getRuntimeParams` function to merge additional varibles to the data loader props when it re-renders so it can fetch the updated data as expected. For example if you had state stored in redux.
You can use the `useRuntimeParams` function to merge additional varibles to the data loader props when it re-renders so it can fetch the updated data as expected. For example if you had state stored in redux.
React hooks are supported inside this function.
```ts

@@ -51,0 +53,0 @@ import { init } from 'json-react-layouts-data-loader'

@@ -15,4 +15,4 @@ import { LayoutApi } from 'json-react-layouts'

> {
/** Hook to provide additional dynamic parameters to the data loader */
getRuntimeParams?: (
/** Custom React Hook to provide additional dynamic parameters to the data loader */
useRuntimeParams?: (
dataDefinitionArgs: DataLoadArguments,

@@ -19,0 +19,0 @@ services: Services,

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

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