dumbmatter / realistic-structured-clone Goto Github PK
View Code? Open in Web Editor NEWA pure JS implementation of the structured clone algorithm (or at least something pretty close to that).
A pure JS implementation of the structured clone algorithm (or at least something pretty close to that).
Native structuredClone
is landing in browsers. It would be great if this forked to use that if it exists.
I'm using dexie-observable
under node.js through fake-indexeddb
. Through a series of events it ends up calling put
on an object with a save
prototype method, which fails because lodash's isPlainObject
returns false:
} else if (!isPlainObject(input)) {
// This is way too restrictive. Should be able to clone any object that isn't
// a platform object with an internal slot other than [[Prototype]] or [[Extensible]].
// But need to reject all platform objects, except those whitelisted for cloning
// (ie, those with a [[Clone]] internal method), and this errs on the side of caution
// for now.
// Supposed to also handle FileList, ImageData, ImageBitmap, but fuck it
throw new DataCloneError();
} else {
According to the structured clone algorithm this should be ok- the object will be duplicated but "The prototype chain does not get walked and duplicated".
For comparison, Chrome's IndexedDB implementation allows the object to be saved.
reference: dexie/Dexie.js#647
I was wondering about this warning from NPM:
npm WARN [email protected] requires a peer of core-js-bundle@^3.6.4 but none is installed. You must install peer dependencies yourself.
So I checked out where this came from:
$ npm ls typeson
safeex_cloud@ /home/jmk/git/my-project
└─┬ [email protected]
└─┬ [email protected]
├── [email protected]
└─┬ [email protected]
└── [email protected]
Seemingly, if you upgrade to the newest typeson
, this warning will disappear.
Version: 2.0.2
const realisticStructuredClone = require("realistic-structured-clone");
const sample = {
"": new Map(),
};
realisticStructuredClone(sample);
The following error is thrown:
TypeError: #<Object> is not iterable
at new Map (<anonymous>)
at Object.revive (<redacted>/node_modules/realistic-structured-clone/dist/index.js:1436:16)
at <redacted>/node_modules/realistic-structured-clone/dist/index.js:1784:156
at Array.reduce (<anonymous>)
at _revive (<redacted>/node_modules/realistic-structured-clone/dist/index.js:1783:43)
at Typeson.c.revive (<redacted>/node_modules/realistic-structure…s/release/async.js:93:12)
at _drainQueue (<redacted>/node_modules/bluebird/js/release/async.js:86:9)
at Async.Object.<anonymous>.Async._drainQueues (<redacted>/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (<redacted>/node_modules/bluebird/js/release/async.js:15:14)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
realisticStructuredClone
should return an object that with a key of ""
and a value that is an empty Map
.
I have a huge array and it takes around 6 seconds to clone in version 1, but around 30 seconds in version 2. Is anyone else seeing this?
hi there!
npm WARN deprecated [email protected]: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
I'm getting it as part of install of another package for which your code is a requirement.
Thanks,
Ben
I'm looking at using fake-indexeddb for faster unit testing.
Upon reading the w3c spec, could the blob implementation be just new Blob([blob])
? On mdn it doesn't appear that close()
is implemented in any browser. Blobs are also immutable so copying the real underlying data isn't necessary. Any thoughts?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.