Closed ghost closed 7 years ago
this would be also useful for redux-devtools where the log monitor is also picking up the methods, making the redux log difficult to read through
In the meantime, I've done the following for using seamless-immutable
with redux-devtools
and redux-devtools-log-monitor
(it's not ideal perf-wise, but does the job):
import React from 'react'
import { createDevTools } from 'redux-devtools'
import LogMonitor from 'redux-devtools-log-monitor'
import DockMonitor from 'redux-devtools-dock-monitor'
import MultipleMonitors from 'redux-devtools-multiple-monitors'
// clone without prototype methods so the seamless-immutable methods aren't exposed in the logs
// http://stackoverflow.com/questions/728360/how-do-i-correctly-clone-a-javascript-object
function clone(obj) {
var copy
// Handle the 3 simple types, and null or undefined
if (null == obj || "object" != typeof obj) return obj
// Handle Date
if (obj instanceof Date) {
copy = new Date()
copy.setTime(obj.getTime())
return copy
}
// Handle Array
if (obj instanceof Array) {
copy = []
for (var i = 0, len = obj.length; i < len; i++) {
copy[i] = clone(obj[i])
}
return copy
}
// Handle Object
if (obj instanceof Object) {
copy = {}
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr])
}
return copy
}
}
export default createDevTools(
<DockMonitor toggleVisibilityKey='ctrl-h' changePositionKey='ctrl-q' defaultIsVisible={false}>
<MultipleMonitors>
<LogMonitor select={clone} />
</MultipleMonitors>
</DockMonitor>
)
FWIW, this would be pretty useful to me as well! I am often debugging objects in the console, and the instance methods often make it harder, so I end up using JSON.stringify()
which isn't as easily browseable.
This issue can be closed - Fixed as of 7.0.0
I really like the project. One thing that I don't find ideal is, that it adds new methods to the object. This way we'd tightly couple our whole app to this lib to perform mutations.
We'd rather just have the benefit of immutable data structure and operate on the data for instance with lodash/ramda/whatever.
In the future, will there be a possibility to deactivate the methods?