Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Handle Date and RegExp Objects #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
24 changes: 20 additions & 4 deletions src/-private/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ import {

const REDUX_PROXY_LABEL = Symbol();

function isValidObject(object) {
/*
Some objects should be treated like primitives.
Their values should be returned instead of a proxy/ObjectTreeNode.
*/

let isValid = false;

if (object !== null && typeof object === 'object') {
isValid = true;
if (object instanceof Date) { isValid = false }
if (object instanceof RegExp) { isValid = false }
}

return isValid;
}

class ObjectTreeNode {
constructor(value) {
this.value = value;
Expand All @@ -33,7 +50,7 @@ const objectProxyHandler = {
let { value } = node;
let childValue = Reflect.get(value, key);

if (typeof childValue === 'object' && childValue !== null) {
if (isValidObject(childValue)) {
let childNode = node.children[key];

if (childNode === undefined) {
Expand Down Expand Up @@ -153,7 +170,7 @@ export function updateNode(node, newValue) {
dirtyTag(tags[key]);
}

if (typeof newChildValue === 'object' && newChildValue !== null) {
if (isValidObject(newChildValue)) {
delete tags[key];
}
}
Expand All @@ -167,8 +184,7 @@ export function updateNode(node, newValue) {
if (childValue === newChildValue) {
continue;
} else if (
typeof newChildValue === 'object' &&
newChildValue !== null &&
isValidObject(newChildValue) &&
Object.getPrototypeOf(newChildValue) === Object.getPrototypeOf(childValue)
) {
updateNode(childNode, newChildValue);
Expand Down