Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Test store data types update & fixes #427

Merged
merged 26 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8619277
:hammer: Rename dataCheck -> dataChanged
T4rk1n Dec 28, 2018
2c123ab
:hammer: Rename dataChanged arguments (newData, oldData)
T4rk1n Dec 28, 2018
a893ce2
:bulb: Add docstring to dataChanged.
T4rk1n Dec 28, 2018
b9311db
:white_check_mark: Add test_store_type_updates
T4rk1n Dec 28, 2018
7160cdb
:lipstick: Run prettier.
T4rk1n Dec 28, 2018
a6ca83c
:hammer: Remove null data check in componentDidUpdate
T4rk1n Dec 28, 2018
101360f
:rotating_light: Add boolean to tested types
T4rk1n Dec 28, 2018
f3dba35
:hammer: Add boolean type check
T4rk1n Dec 28, 2018
2b31866
:hammer: Add type difference check
T4rk1n Dec 28, 2018
1384df8
:rotating_light: Fix type test number, present before updated.
T4rk1n Dec 28, 2018
905063f
:hammer: Improve wait_for_text_to_equal
T4rk1n Dec 28, 2018
f2bbe13
:hammer: Import ramda functions instead of R
T4rk1n Dec 28, 2018
81ad362
:bulb: Add docstring to stores abstractions classes.
T4rk1n Dec 28, 2018
4dea91a
:rotating_light: Add edge case types test.
T4rk1n Jan 7, 2019
7afbe92
:hocho: Remove same type comment.
T4rk1n Jan 7, 2019
0dd6387
:bug: Fix Store key removal from dict.
T4rk1n Jan 7, 2019
a3af1ea
:lipstick: Run prettier
T4rk1n Jan 7, 2019
ba0fd27
:package: Update bundles
T4rk1n Jan 7, 2019
ae9bc3f
:pencil: Update changelog
T4rk1n Jan 7, 2019
7e276fe
:bookmark: Version 0.42.1
T4rk1n Jan 7, 2019
81e2d34
:rotating_light: Add null edge case
T4rk1n Jan 8, 2019
2d0d43c
:hammer: Move list-dict to edge cases.
T4rk1n Jan 8, 2019
a482f79
:hocho: Remove test_store_null_values
T4rk1n Jan 8, 2019
a6bd791
:rotating_light: Test none in list in types combinations.
T4rk1n Jan 8, 2019
ef16ed1
:ok_hand: Check data instead of null after null check.
T4rk1n Jan 8, 2019
9093035
:package: Update bundles
T4rk1n Jan 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.42.1] - 2019-01-07
### Fixed
- Fix `dcc.Store` type changes [#427](https://github.com/plotly/dash-core-components/pull/427)

## [0.42.0] - 2018-12-27
### Fixed
- Fix `dcc.Store` null values in list causing an infinite loop [#424](https://github.com/plotly/dash-core-components/pull/424)
Expand Down
89 changes: 60 additions & 29 deletions dash_core_components/dash_core_components.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -114609,42 +114609,65 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }



/**
* Deep equality check to know if the data has changed.
*
* @param {*} newData - New data to compare
* @param {*} oldData - The old data to compare
* @returns {boolean} The data has changed.
*/

function dataCheck(data, old) {
// Assuming data and old are of the same type.
var oldNull = ramda__WEBPACK_IMPORTED_MODULE_0___default.a.isNil(old);
var newNull = ramda__WEBPACK_IMPORTED_MODULE_0___default.a.isNil(data);
function dataChanged(newData, oldData) {
var oldNull = Object(ramda__WEBPACK_IMPORTED_MODULE_0__["isNil"])(oldData);
var newNull = Object(ramda__WEBPACK_IMPORTED_MODULE_0__["isNil"])(newData);

if ((oldNull || newNull) && !(oldNull && newNull)) {
return true;
if (oldNull || newNull) {
return oldNull !== newNull;
}

var type = ramda__WEBPACK_IMPORTED_MODULE_0___default.a.type(data);
var newType = Object(ramda__WEBPACK_IMPORTED_MODULE_0__["type"])(newData);

if (type === 'Array') {
if (data.length !== old.length) {
if (newType !== Object(ramda__WEBPACK_IMPORTED_MODULE_0__["type"])(oldData)) {
return true;
}

if (newType === 'Array') {
if (newData.length !== oldData.length) {
return true;
}

for (var i = 0; i < data.length; i++) {
if (dataCheck(data[i], old[i])) {
for (var i = 0; i < newData.length; i++) {
if (dataChanged(newData[i], oldData[i])) {
return true;
}
}
} else if (ramda__WEBPACK_IMPORTED_MODULE_0___default.a.contains(type, ['String', 'Number'])) {
return old !== data;
} else if (type === 'Object') {
return ramda__WEBPACK_IMPORTED_MODULE_0___default.a.any(function (_ref) {
} else if (Object(ramda__WEBPACK_IMPORTED_MODULE_0__["contains"])(newType, ['String', 'Number', 'Boolean'])) {
return oldData !== newData;
} else if (newType === 'Object') {
var oldEntries = Object.entries(oldData);
var newEntries = Object.entries(newData);

if (oldEntries.length !== newEntries.length) {
return true;
}

return Object(ramda__WEBPACK_IMPORTED_MODULE_0__["any"])(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
k = _ref2[0],
v = _ref2[1];

return dataCheck(v, old[k]);
})(Object.entries(data));
return dataChanged(v, oldData[k]);
})(newEntries);
}

return false;
}
/**
* Abstraction for the memory storage_type to work the same way as local/session
*
* Each memory Store component get it's own MemStore.
*/


var MemStore =
/*#__PURE__*/
Expand Down Expand Up @@ -114689,6 +114712,12 @@ function () {

return MemStore;
}();
/**
* Abstraction for local/session storage_type.
*
* Single instances for localStorage, sessionStorage
*/


var WebStore =
/*#__PURE__*/
Expand Down Expand Up @@ -114797,7 +114826,7 @@ function (_React$Component) {

var old = this._backstore.getItem(id);

if (ramda__WEBPACK_IMPORTED_MODULE_0___default.a.isNil(old) && data) {
if (Object(ramda__WEBPACK_IMPORTED_MODULE_0__["isNil"])(old) && data) {
// Initial data mount
this._backstore.setItem(id, data);

Expand All @@ -114810,7 +114839,7 @@ function (_React$Component) {
return;
}

if (setProps && dataCheck(old, data)) {
if (setProps && dataChanged(old, data)) {
setProps({
data: old,
modified_timestamp: this._backstore.getModified(id)
Expand Down Expand Up @@ -114843,18 +114872,20 @@ function (_React$Component) {
modified_timestamp: this._backstore.getModified(id)
});
}
} else if (data) {
var old = this._backstore.getItem(id); // Only set the data if it's not the same data.

return;
}

if (dataCheck(data, old)) {
this._backstore.setItem(id, data);
var old = this._backstore.getItem(id); // Only set the data if it's not the same data.

if (setProps) {
setProps({
modified_timestamp: this._backstore.getModified(id)
});
}

if (dataChanged(data, old)) {
this._backstore.setItem(id, data);

if (setProps) {
setProps({
modified_timestamp: this._backstore.getModified(id)
});
}
}
}
Expand Down Expand Up @@ -114892,7 +114923,7 @@ Store.propTypes = {
/**
* The stored data for the id.
*/
data: prop_types__WEBPACK_IMPORTED_MODULE_2___default.a.oneOfType([prop_types__WEBPACK_IMPORTED_MODULE_2___default.a.object, prop_types__WEBPACK_IMPORTED_MODULE_2___default.a.array, prop_types__WEBPACK_IMPORTED_MODULE_2___default.a.number, prop_types__WEBPACK_IMPORTED_MODULE_2___default.a.string]),
data: prop_types__WEBPACK_IMPORTED_MODULE_2___default.a.oneOfType([prop_types__WEBPACK_IMPORTED_MODULE_2___default.a.object, prop_types__WEBPACK_IMPORTED_MODULE_2___default.a.array, prop_types__WEBPACK_IMPORTED_MODULE_2___default.a.number, prop_types__WEBPACK_IMPORTED_MODULE_2___default.a.string, prop_types__WEBPACK_IMPORTED_MODULE_2___default.a.bool]),

/**
* Set to true to remove the data contained in `data_key`.
Expand Down
2 changes: 1 addition & 1 deletion dash_core_components/dash_core_components.dev.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dash_core_components/dash_core_components.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dash_core_components/dash_core_components.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dash_core_components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dash-core-components",
"version": "0.42.0",
"version": "0.42.1",
"description": "Core component suite for Dash",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion dash_core_components/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.42.0'
__version__ = '0.42.1'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dash-core-components",
"version": "0.42.0",
"version": "0.42.1",
"description": "Core component suite for Dash",
"repository": {
"type": "git",
Expand Down
77 changes: 51 additions & 26 deletions src/components/Store.react.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,51 @@
import R from 'ramda';
import {isNil, type, contains, any} from 'ramda';
import React from 'react';
import PropTypes from 'prop-types';

function dataCheck(data, old) {
// Assuming data and old are of the same type.
const oldNull = R.isNil(old);
const newNull = R.isNil(data);
/**
* Deep equality check to know if the data has changed.
*
* @param {*} newData - New data to compare
* @param {*} oldData - The old data to compare
* @returns {boolean} The data has changed.
*/
function dataChanged(newData, oldData) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful, thank you!

const oldNull = isNil(oldData);
const newNull = isNil(newData);
if (oldNull || newNull) {
return oldNull !== newNull;
}
const type = R.type(data);
if (type === 'Array') {
if (data.length !== old.length) {
const newType = type(newData);
if (newType !== type(oldData)) {
return true;
}
if (newType === 'Array') {
if (newData.length !== oldData.length) {
return true;
}
for (let i = 0; i < data.length; i++) {
if (dataCheck(data[i], old[i])) {
for (let i = 0; i < newData.length; i++) {
if (dataChanged(newData[i], oldData[i])) {
return true;
}
}
} else if (R.contains(type, ['String', 'Number'])) {
return old !== data;
} else if (type === 'Object') {
return R.any(([k, v]) => dataCheck(v, old[k]))(Object.entries(data));
} else if (contains(newType, ['String', 'Number', 'Boolean'])) {
return oldData !== newData;
} else if (newType === 'Object') {
const oldEntries = Object.entries(oldData);
const newEntries = Object.entries(newData);
if (oldEntries.length !== newEntries.length) {
return true;
}
return any(([k, v]) => dataChanged(v, oldData[k]))(newEntries);
}
return false;
}

/**
* Abstraction for the memory storage_type to work the same way as local/session
*
* Each memory Store component get it's own MemStore.
*/
class MemStore {
constructor() {
this._data = {};
Expand Down Expand Up @@ -58,6 +77,11 @@ class MemStore {
}
}

/**
* Abstraction for local/session storage_type.
*
* Single instances for localStorage, sessionStorage
*/
class WebStore {
constructor(storage) {
this._storage = storage;
Expand Down Expand Up @@ -129,7 +153,7 @@ export default class Store extends React.Component {
}

const old = this._backstore.getItem(id);
if (R.isNil(old) && data) {
if (isNil(old) && data) {
// Initial data mount
this._backstore.setItem(id, data);
if (setProps) {
Expand All @@ -140,7 +164,7 @@ export default class Store extends React.Component {
return;
}

if (setProps && dataCheck(old, data)) {
if (setProps && dataChanged(old, data)) {
setProps({
data: old,
modified_timestamp: this._backstore.getModified(id),
Expand All @@ -165,16 +189,16 @@ export default class Store extends React.Component {
modified_timestamp: this._backstore.getModified(id),
});
}
} else if (data) {
const old = this._backstore.getItem(id);
// Only set the data if it's not the same data.
if (dataCheck(data, old)) {
this._backstore.setItem(id, data);
if (setProps) {
setProps({
modified_timestamp: this._backstore.getModified(id),
});
}
return;
}
const old = this._backstore.getItem(id);
// Only set the data if it's not the same data.
if (dataChanged(data, old)) {
this._backstore.setItem(id, data);
if (setProps) {
setProps({
modified_timestamp: this._backstore.getModified(id),
});
}
}
}
Expand Down Expand Up @@ -213,6 +237,7 @@ Store.propTypes = {
PropTypes.array,
PropTypes.number,
PropTypes.string,
PropTypes.bool,
]),

/**
Expand Down
Loading