Deep spread operator (Bilal Abdullah)
IMO, this would be very problematic.
-
4 dots are visually almost identical to 3 dots. This could introduce severe bugs because of a simple hard to spot typo.
-
Deep traversing will always have performance problems in some cases. Dealing with circular references can take this issue even further.
I believe such functionality should be used in very specific situations, where object shape is well-known, not very deep and definitely not circular. So, supporting this at the core of the language will probably be frowned upon by the community.
Em ter, 23 de out de 2018 08:57, Ahad Cove <ahadcove at gmail.com> escreveu:
IMO, this would be very problematic. 1. 4 dots are visually almost identical to 3 dots. This could introduce severe bugs because of a simple hard to spot typo. 2. Deep traversing will always have performance problems in some cases. Dealing with circular references can take this issue even further. I believe such functionality should be used in very specific situations, where object shape is well-known, not very deep and definitely not circular. So, supporting this at the core of the language will probably be frowned upon by the community. Em ter, 23 de out de 2018 08:57, Ahad Cove <ahadcove at gmail.com> escreveu: > Hello Scripters, > > I really appreciate everything you all have done for the language and have > no complaints over here. > I do have a suggestion though :) > > At work we’ve almost got rid of lodash, except we still need it for > DeepCopy vs rolling our own. > It’s the same with my side projects. I don’t use lodash because the main > times that I need deep copy is when I’m either digging into the Redux store > using React, or copying an observable in the Angular world. > > I believe ES Script users would appreciate having a deep copy spread > operator tremendously. > > My proposal is to go off of the current spread operator we currently have > in ES and make it 4 dots for a deep spread. This can be used on Objects or > Arrays. > > ‘’’js > const oldDeepObj = { > InnerObj: { > func: () => return ‘wow’ > } > } > > const obj = {....oldDeepObj} > obj.innerObj.func = () => return ‘nice’ > > oldDeepObj.innerObj.func() > > wow > ‘’’ > > Thank you! > Looking forward to hearing back from you all. > If there’s any other questions let me know > > - Bilal Abdullah > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -- Henrique -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181023/5e122a7f/attachment.html>
Is there any real problem with circular reference cloning? I don't see any, Please let me know in the simplest case e.g. { a: a } (obviously contrived syntax here)
Otherwise, I agree completely about the 4 dots being the wrong syntax for this, precisely for the reason you gave
Is there any real problem with circular reference cloning? I don't see any, Please let me know in the simplest case e.g. { a: a } (obviously contrived syntax here) Otherwise, I agree completely about the 4 dots being the wrong syntax for this, precisely for the reason you gave On Tue, 23 Oct 2018 at 18:18 Henrique Barcelos <rick.hjpbarcelos at gmail.com> wrote: > IMO, this would be very problematic. > > 1. 4 dots are visually almost identical to 3 dots. This could introduce > severe bugs because of a simple hard to spot typo. > > 2. Deep traversing will always have performance problems in some cases. > Dealing with circular references can take this issue even further. > > I believe such functionality should be used in very specific situations, > where object shape is well-known, not very deep and definitely not > circular. So, supporting this at the core of the language will probably be > frowned upon by the community. > > Em ter, 23 de out de 2018 08:57, Ahad Cove <ahadcove at gmail.com> escreveu: > >> Hello Scripters, >> >> I really appreciate everything you all have done for the language and >> have no complaints over here. >> I do have a suggestion though :) >> >> At work we’ve almost got rid of lodash, except we still need it for >> DeepCopy vs rolling our own. >> It’s the same with my side projects. I don’t use lodash because the main >> times that I need deep copy is when I’m either digging into the Redux store >> using React, or copying an observable in the Angular world. >> >> I believe ES Script users would appreciate having a deep copy spread >> operator tremendously. >> >> My proposal is to go off of the current spread operator we currently have >> in ES and make it 4 dots for a deep spread. This can be used on Objects or >> Arrays. >> >> ‘’’js >> const oldDeepObj = { >> InnerObj: { >> func: () => return ‘wow’ >> } >> } >> >> const obj = {....oldDeepObj} >> obj.innerObj.func = () => return ‘nice’ >> >> oldDeepObj.innerObj.func() >> > wow >> ‘’’ >> >> Thank you! >> Looking forward to hearing back from you all. >> If there’s any other questions let me know >> >> - Bilal Abdullah >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> > -- > > Henrique > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181023/86d745d6/attachment.html>
Correction, suppose const b = { a : b } . Circular references can be cloned trivially, as far as I can tell
Correction, suppose const b = { a : b } . Circular references can be cloned trivially, as far as I can tell On Tue, 23 Oct 2018 at 20:52 Naveen Chawla <naveen.chwl at gmail.com> wrote: > Is there any real problem with circular reference cloning? I don't see > any, Please let me know in the simplest case e.g. { a: a } (obviously > contrived syntax here) > > Otherwise, I agree completely about the 4 dots being the wrong syntax for > this, precisely for the reason you gave > > On Tue, 23 Oct 2018 at 18:18 Henrique Barcelos <rick.hjpbarcelos at gmail.com> > wrote: > >> IMO, this would be very problematic. >> >> 1. 4 dots are visually almost identical to 3 dots. This could introduce >> severe bugs because of a simple hard to spot typo. >> >> 2. Deep traversing will always have performance problems in some cases. >> Dealing with circular references can take this issue even further. >> >> I believe such functionality should be used in very specific situations, >> where object shape is well-known, not very deep and definitely not >> circular. So, supporting this at the core of the language will probably be >> frowned upon by the community. >> >> Em ter, 23 de out de 2018 08:57, Ahad Cove <ahadcove at gmail.com> escreveu: >> >>> Hello Scripters, >>> >>> I really appreciate everything you all have done for the language and >>> have no complaints over here. >>> I do have a suggestion though :) >>> >>> At work we’ve almost got rid of lodash, except we still need it for >>> DeepCopy vs rolling our own. >>> It’s the same with my side projects. I don’t use lodash because the main >>> times that I need deep copy is when I’m either digging into the Redux store >>> using React, or copying an observable in the Angular world. >>> >>> I believe ES Script users would appreciate having a deep copy spread >>> operator tremendously. >>> >>> My proposal is to go off of the current spread operator we currently >>> have in ES and make it 4 dots for a deep spread. This can be used on >>> Objects or Arrays. >>> >>> ‘’’js >>> const oldDeepObj = { >>> InnerObj: { >>> func: () => return ‘wow’ >>> } >>> } >>> >>> const obj = {....oldDeepObj} >>> obj.innerObj.func = () => return ‘nice’ >>> >>> oldDeepObj.innerObj.func() >>> > wow >>> ‘’’ >>> >>> Thank you! >>> Looking forward to hearing back from you all. >>> If there’s any other questions let me know >>> >>> - Bilal Abdullah >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >> -- >> >> Henrique >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181023/e30a73e7/attachment-0001.html>
there’s no reliable way to deep-copy arbitrary js-objects. the most practical “general” solution is two-step:
- deep-copy JSON-data first, e.g.
var bb = JSON.parse(JSON.stringify(aa))
- custom-copy non-JSON-data in a second-pass, e.g.
bb.innerObj.func = aa.innerObj.func
like this real-world example [1]:
local.jsonCopy = function (obj) {
/*
* this function will [JSON] deep-copy obj
*/
return obj === undefined
? undefined
: JSON.parse(JSON.stringify(obj));
};
...
// update apiDict
self = local.apiDict[key.join('.')] = local.apiDict[self._methodPath] =
local.jsonCopy(self); // step 1 - deep-copy JSON-data first
// init ajax
self.ajax = function (swaggerJson, onError) { // step 2 - custom-copy/add non-JSON-data in second-pass
return local.apiAjax(self, swaggerJson, onError);
};
[1] deep-copy swagger client-object with functions kaizhu256/node-swgg/blob/2018.9.8/lib.swgg.js#L2181
kai zhu kaizhu256 at gmail.com
hi Bilai, there’s no reliable way to deep-copy arbitrary js-objects. the most practical “general” solution is two-step: 1. deep-copy JSON-data first, e.g. ```var bb = JSON.parse(JSON.stringify(aa))``` 2. custom-copy non-JSON-data in a second-pass, e.g. ```bb.innerObj.func = aa.innerObj.func``` like this real-world example [1]: ```javascript local.jsonCopy = function (obj) { /* * this function will [JSON] deep-copy obj */ return obj === undefined ? undefined : JSON.parse(JSON.stringify(obj)); }; ... // update apiDict self = local.apiDict[key.join('.')] = local.apiDict[self._methodPath] = local.jsonCopy(self); // step 1 - deep-copy JSON-data first // init ajax self.ajax = function (swaggerJson, onError) { // step 2 - custom-copy/add non-JSON-data in second-pass return local.apiAjax(self, swaggerJson, onError); }; ``` [1] deep-copy swagger client-object with functions https://github.com/kaizhu256/node-swgg/blob/2018.9.8/lib.swgg.js#L2181 kai zhu kaizhu256 at gmail.com > On 23 Oct 2018, at 10:25 PM, Naveen Chawla <naveen.chwl at gmail.com> wrote: > > Correction, suppose const b = { a : b } . Circular references can be cloned trivially, as far as I can tell > > On Tue, 23 Oct 2018 at 20:52 Naveen Chawla <naveen.chwl at gmail.com <mailto:naveen.chwl at gmail.com>> wrote: > Is there any real problem with circular reference cloning? I don't see any, Please let me know in the simplest case e.g. { a: a } (obviously contrived syntax here) > > Otherwise, I agree completely about the 4 dots being the wrong syntax for this, precisely for the reason you gave > > On Tue, 23 Oct 2018 at 18:18 Henrique Barcelos <rick.hjpbarcelos at gmail.com <mailto:rick.hjpbarcelos at gmail.com>> wrote: > IMO, this would be very problematic. > > 1. 4 dots are visually almost identical to 3 dots. This could introduce severe bugs because of a simple hard to spot typo. > > 2. Deep traversing will always have performance problems in some cases. Dealing with circular references can take this issue even further. > > I believe such functionality should be used in very specific situations, where object shape is well-known, not very deep and definitely not circular. So, supporting this at the core of the language will probably be frowned upon by the community. > > Em ter, 23 de out de 2018 08:57, Ahad Cove <ahadcove at gmail.com <mailto:ahadcove at gmail.com>> escreveu: > Hello Scripters, > > I really appreciate everything you all have done for the language and have no complaints over here. > I do have a suggestion though :) > > At work we’ve almost got rid of lodash, except we still need it for DeepCopy vs rolling our own. > It’s the same with my side projects. I don’t use lodash because the main times that I need deep copy is when I’m either digging into the Redux store using React, or copying an observable in the Angular world. > > I believe ES Script users would appreciate having a deep copy spread operator tremendously. > > My proposal is to go off of the current spread operator we currently have in ES and make it 4 dots for a deep spread. This can be used on Objects or Arrays. > > ‘’’js > const oldDeepObj = { > InnerObj: { > func: () => return ‘wow’ > } > } > > const obj = {....oldDeepObj} > obj.innerObj.func = () => return ‘nice’ > > oldDeepObj.innerObj.func() > > wow > ‘’’ > > Thank you! > Looking forward to hearing back from you all. > If there’s any other questions let me know > > - Bilal Abdullah > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> > https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss> > -- > Henrique > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> > https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss> > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181023/7c785d33/attachment.html>
4 dots is already valid syntax when it has a number after it
let o = { ....4 }
4 dots is already valid syntax when it has a number after it let o = { ....4 } On Tue, Oct 23, 2018 at 9:05 AM kai zhu <kaizhu256 at gmail.com> wrote: > hi Bilai, there’s no reliable way to deep-copy arbitrary js-objects. the > most practical “general” solution is two-step: > > 1. deep-copy JSON-data first, e.g. ```var bb = > JSON.parse(JSON.stringify(aa))``` > 2. custom-copy non-JSON-data in a second-pass, e.g. ```bb.innerObj.func = > aa.innerObj.func``` > > like this real-world example [1]: > > ```javascript > local.jsonCopy = function (obj) { > /* > * this function will [JSON] deep-copy obj > */ > return obj === undefined > ? undefined > : JSON.parse(JSON.stringify(obj)); > }; > ... > // update apiDict > self = local.apiDict[key.join('.')] = local.apiDict[self._methodPath] = > local.jsonCopy(self); // step 1 - deep-copy JSON-data first > // init ajax > self.ajax = function (swaggerJson, onError) { // step 2 - custom-copy/add > non-JSON-data in second-pass > return local.apiAjax(self, swaggerJson, onError); > }; > ``` > > [1] deep-copy swagger client-object with functions > https://github.com/kaizhu256/node-swgg/blob/2018.9.8/lib.swgg.js#L2181 > > kai zhu > kaizhu256 at gmail.com > > > > On 23 Oct 2018, at 10:25 PM, Naveen Chawla <naveen.chwl at gmail.com> wrote: > > Correction, suppose const b = { a : b } . Circular references can be > cloned trivially, as far as I can tell > > On Tue, 23 Oct 2018 at 20:52 Naveen Chawla <naveen.chwl at gmail.com> wrote: > >> Is there any real problem with circular reference cloning? I don't see >> any, Please let me know in the simplest case e.g. { a: a } (obviously >> contrived syntax here) >> >> Otherwise, I agree completely about the 4 dots being the wrong syntax for >> this, precisely for the reason you gave >> >> On Tue, 23 Oct 2018 at 18:18 Henrique Barcelos < >> rick.hjpbarcelos at gmail.com> wrote: >> >>> IMO, this would be very problematic. >>> >>> 1. 4 dots are visually almost identical to 3 dots. This could introduce >>> severe bugs because of a simple hard to spot typo. >>> >>> 2. Deep traversing will always have performance problems in some cases. >>> Dealing with circular references can take this issue even further. >>> >>> I believe such functionality should be used in very specific situations, >>> where object shape is well-known, not very deep and definitely not >>> circular. So, supporting this at the core of the language will probably be >>> frowned upon by the community. >>> >>> Em ter, 23 de out de 2018 08:57, Ahad Cove <ahadcove at gmail.com> >>> escreveu: >>> >>>> Hello Scripters, >>>> >>>> I really appreciate everything you all have done for the language and >>>> have no complaints over here. >>>> I do have a suggestion though :) >>>> >>>> At work we’ve almost got rid of lodash, except we still need it for >>>> DeepCopy vs rolling our own. >>>> It’s the same with my side projects. I don’t use lodash because the >>>> main times that I need deep copy is when I’m either digging into the Redux >>>> store using React, or copying an observable in the Angular world. >>>> >>>> I believe ES Script users would appreciate having a deep copy spread >>>> operator tremendously. >>>> >>>> My proposal is to go off of the current spread operator we currently >>>> have in ES and make it 4 dots for a deep spread. This can be used on >>>> Objects or Arrays. >>>> >>>> ‘’’js >>>> const oldDeepObj = { >>>> InnerObj: { >>>> func: () => return ‘wow’ >>>> } >>>> } >>>> >>>> const obj = {....oldDeepObj} >>>> obj.innerObj.func = () => return ‘nice’ >>>> >>>> oldDeepObj.innerObj.func() >>>> > wow >>>> ‘’’ >>>> >>>> Thank you! >>>> Looking forward to hearing back from you all. >>>> If there’s any other questions let me know >>>> >>>> - Bilal Abdullah >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>> -- >>> >>> Henrique >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >> _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181023/086b8f44/attachment-0001.html>
digressing a bit, but once you get used to the idea of deep-copying objects using JSON.parse(JSON.stringify(x)), you also realize web-projects are alot simpler if you keep many non-JSON-datatypes in string-form by default (BigInt, Date, CivilXxx, etc.), since the use-case to copy/serialize data between web-components is far more common than the need to actually revive data for use in low-level business-logic.
kai zhu kaizhu256 at gmail.com
digressing a bit, but once you get used to the idea of deep-copying objects using JSON.parse(JSON.stringify(x)), you also realize web-projects are alot simpler if you keep many non-JSON-datatypes in string-form by default (BigInt, Date, CivilXxx, etc.), since the use-case to copy/serialize data between web-components is far more common than the need to actually revive data for use in low-level business-logic. kai zhu kaizhu256 at gmail.com > On 24 Oct 2018, at 2:22 AM, Jamie <me at thejameskyle.com> wrote: > > 4 dots is already valid syntax when it has a number after it > > let o = { ....4 } > > > On Tue, Oct 23, 2018 at 9:05 AM kai zhu <kaizhu256 at gmail.com <mailto:kaizhu256 at gmail.com>> wrote: > hi Bilai, there’s no reliable way to deep-copy arbitrary js-objects. the most practical “general” solution is two-step: > > 1. deep-copy JSON-data first, e.g. ```var bb = JSON.parse(JSON.stringify(aa))``` > 2. custom-copy non-JSON-data in a second-pass, e.g. ```bb.innerObj.func = aa.innerObj.func``` > > like this real-world example [1]: > > ```javascript > local.jsonCopy = function (obj) { > /* > * this function will [JSON] deep-copy obj > */ > return obj === undefined > ? undefined > : JSON.parse(JSON.stringify(obj)); > }; > ... > // update apiDict > self = local.apiDict[key.join('.')] = local.apiDict[self._methodPath] = > local.jsonCopy(self); // step 1 - deep-copy JSON-data first > // init ajax > self.ajax = function (swaggerJson, onError) { // step 2 - custom-copy/add non-JSON-data in second-pass > return local.apiAjax(self, swaggerJson, onError); > }; > ``` > > [1] deep-copy swagger client-object with functions > https://github.com/kaizhu256/node-swgg/blob/2018.9.8/lib.swgg.js#L2181 <https://github.com/kaizhu256/node-swgg/blob/2018.9.8/lib.swgg.js#L2181> > > kai zhu > kaizhu256 at gmail.com <mailto:kaizhu256 at gmail.com> > > > >> On 23 Oct 2018, at 10:25 PM, Naveen Chawla <naveen.chwl at gmail.com <mailto:naveen.chwl at gmail.com>> wrote: >> >> Correction, suppose const b = { a : b } . Circular references can be cloned trivially, as far as I can tell >> >> On Tue, 23 Oct 2018 at 20:52 Naveen Chawla <naveen.chwl at gmail.com <mailto:naveen.chwl at gmail.com>> wrote: >> Is there any real problem with circular reference cloning? I don't see any, Please let me know in the simplest case e.g. { a: a } (obviously contrived syntax here) >> >> Otherwise, I agree completely about the 4 dots being the wrong syntax for this, precisely for the reason you gave >> >> On Tue, 23 Oct 2018 at 18:18 Henrique Barcelos <rick.hjpbarcelos at gmail.com <mailto:rick.hjpbarcelos at gmail.com>> wrote: >> IMO, this would be very problematic. >> >> 1. 4 dots are visually almost identical to 3 dots. This could introduce severe bugs because of a simple hard to spot typo. >> >> 2. Deep traversing will always have performance problems in some cases. Dealing with circular references can take this issue even further. >> >> I believe such functionality should be used in very specific situations, where object shape is well-known, not very deep and definitely not circular. So, supporting this at the core of the language will probably be frowned upon by the community. >> >> Em ter, 23 de out de 2018 08:57, Ahad Cove <ahadcove at gmail.com <mailto:ahadcove at gmail.com>> escreveu: >> Hello Scripters, >> >> I really appreciate everything you all have done for the language and have no complaints over here. >> I do have a suggestion though :) >> >> At work we’ve almost got rid of lodash, except we still need it for DeepCopy vs rolling our own. >> It’s the same with my side projects. I don’t use lodash because the main times that I need deep copy is when I’m either digging into the Redux store using React, or copying an observable in the Angular world. >> >> I believe ES Script users would appreciate having a deep copy spread operator tremendously. >> >> My proposal is to go off of the current spread operator we currently have in ES and make it 4 dots for a deep spread. This can be used on Objects or Arrays. >> >> ‘’’js >> const oldDeepObj = { >> InnerObj: { >> func: () => return ‘wow’ >> } >> } >> >> const obj = {....oldDeepObj} >> obj.innerObj.func = () => return ‘nice’ >> >> oldDeepObj.innerObj.func() >> > wow >> ‘’’ >> >> Thank you! >> Looking forward to hearing back from you all. >> If there’s any other questions let me know >> >> - Bilal Abdullah >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> >> https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss> >> -- >> Henrique >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> >> https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> >> https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> > https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181024/50327b9f/attachment.html>
both CircularJSON (deprecated) and flatted (the successor) easily deal with circular references while serializing / unserializing objects, yet you need to keep stored data simple.
This is usually a common case for postMessage / workers though, so it shouldn't be a big deal.
stringifiers and revivers can give you extra power to serialize /
unserialize RegExps, Date, as well as BigInt too, storing values via
{new:'RegExp',args:['value', 'gi']}
simplifying the case for
{new:'Array', args:[...the-actual-array]}
and {new: 'Object', args: [..the-actual-object...]}
Well, I'm sure you got there are many ways to deep copy and also with circular references.
both CircularJSON (deprecated) and flatted (the successor) easily deal with circular references while serializing / unserializing objects, yet you need to keep stored data simple. This is usually a common case for postMessage / workers though, so it shouldn't be a big deal. stringifiers and revivers can give you extra power to serialize / unserialize RegExps, Date, as well as BigInt too, storing values via `{new:'RegExp',args:['value', 'gi']}` simplifying the case for `{new:'Array', args:[...the-actual-array]}` and `{new: 'Object', args: [..the-actual-object...]}` Well, I'm sure you got there are many ways to deep copy and also with circular references. Regards On Tue, Oct 23, 2018 at 5:23 PM Naveen Chawla <naveen.chwl at gmail.com> wrote: > Is there any real problem with circular reference cloning? I don't see > any, Please let me know in the simplest case e.g. { a: a } (obviously > contrived syntax here) > > Otherwise, I agree completely about the 4 dots being the wrong syntax for > this, precisely for the reason you gave > > On Tue, 23 Oct 2018 at 18:18 Henrique Barcelos <rick.hjpbarcelos at gmail.com> > wrote: > >> IMO, this would be very problematic. >> >> 1. 4 dots are visually almost identical to 3 dots. This could introduce >> severe bugs because of a simple hard to spot typo. >> >> 2. Deep traversing will always have performance problems in some cases. >> Dealing with circular references can take this issue even further. >> >> I believe such functionality should be used in very specific situations, >> where object shape is well-known, not very deep and definitely not >> circular. So, supporting this at the core of the language will probably be >> frowned upon by the community. >> >> Em ter, 23 de out de 2018 08:57, Ahad Cove <ahadcove at gmail.com> escreveu: >> >>> Hello Scripters, >>> >>> I really appreciate everything you all have done for the language and >>> have no complaints over here. >>> I do have a suggestion though :) >>> >>> At work we’ve almost got rid of lodash, except we still need it for >>> DeepCopy vs rolling our own. >>> It’s the same with my side projects. I don’t use lodash because the main >>> times that I need deep copy is when I’m either digging into the Redux store >>> using React, or copying an observable in the Angular world. >>> >>> I believe ES Script users would appreciate having a deep copy spread >>> operator tremendously. >>> >>> My proposal is to go off of the current spread operator we currently >>> have in ES and make it 4 dots for a deep spread. This can be used on >>> Objects or Arrays. >>> >>> ‘’’js >>> const oldDeepObj = { >>> InnerObj: { >>> func: () => return ‘wow’ >>> } >>> } >>> >>> const obj = {....oldDeepObj} >>> obj.innerObj.func = () => return ‘nice’ >>> >>> oldDeepObj.innerObj.func() >>> > wow >>> ‘’’ >>> >>> Thank you! >>> Looking forward to hearing back from you all. >>> If there’s any other questions let me know >>> >>> - Bilal Abdullah >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >> -- >> >> Henrique >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181024/2066709d/attachment-0001.html>
I think a combination of Object.entries, .flatMap and Object.fromEntries could do the job
I think a combination of Object.entries, .flatMap and Object.fromEntries could do the job On Wed, Oct 24, 2018 at 1:12 PM Andrea Giammarchi < andrea.giammarchi at gmail.com> wrote: > both CircularJSON (deprecated) and flatted (the successor) easily deal > with circular references while serializing / unserializing objects, yet you > need to keep stored data simple. > > This is usually a common case for postMessage / workers though, so it > shouldn't be a big deal. > > stringifiers and revivers can give you extra power to serialize / > unserialize RegExps, Date, as well as BigInt too, storing values via > `{new:'RegExp',args:['value', 'gi']}` simplifying the case for > `{new:'Array', args:[...the-actual-array]}` and `{new: 'Object', args: > [..the-actual-object...]}` > > Well, I'm sure you got there are many ways to deep copy and also with > circular references. > > Regards > > > On Tue, Oct 23, 2018 at 5:23 PM Naveen Chawla <naveen.chwl at gmail.com> > wrote: > >> Is there any real problem with circular reference cloning? I don't see >> any, Please let me know in the simplest case e.g. { a: a } (obviously >> contrived syntax here) >> >> Otherwise, I agree completely about the 4 dots being the wrong syntax for >> this, precisely for the reason you gave >> >> On Tue, 23 Oct 2018 at 18:18 Henrique Barcelos < >> rick.hjpbarcelos at gmail.com> wrote: >> >>> IMO, this would be very problematic. >>> >>> 1. 4 dots are visually almost identical to 3 dots. This could introduce >>> severe bugs because of a simple hard to spot typo. >>> >>> 2. Deep traversing will always have performance problems in some cases. >>> Dealing with circular references can take this issue even further. >>> >>> I believe such functionality should be used in very specific situations, >>> where object shape is well-known, not very deep and definitely not >>> circular. So, supporting this at the core of the language will probably be >>> frowned upon by the community. >>> >>> Em ter, 23 de out de 2018 08:57, Ahad Cove <ahadcove at gmail.com> >>> escreveu: >>> >>>> Hello Scripters, >>>> >>>> I really appreciate everything you all have done for the language and >>>> have no complaints over here. >>>> I do have a suggestion though :) >>>> >>>> At work we’ve almost got rid of lodash, except we still need it for >>>> DeepCopy vs rolling our own. >>>> It’s the same with my side projects. I don’t use lodash because the >>>> main times that I need deep copy is when I’m either digging into the Redux >>>> store using React, or copying an observable in the Angular world. >>>> >>>> I believe ES Script users would appreciate having a deep copy spread >>>> operator tremendously. >>>> >>>> My proposal is to go off of the current spread operator we currently >>>> have in ES and make it 4 dots for a deep spread. This can be used on >>>> Objects or Arrays. >>>> >>>> ‘’’js >>>> const oldDeepObj = { >>>> InnerObj: { >>>> func: () => return ‘wow’ >>>> } >>>> } >>>> >>>> const obj = {....oldDeepObj} >>>> obj.innerObj.func = () => return ‘nice’ >>>> >>>> oldDeepObj.innerObj.func() >>>> > wow >>>> ‘’’ >>>> >>>> Thank you! >>>> Looking forward to hearing back from you all. >>>> If there’s any other questions let me know >>>> >>>> - Bilal Abdullah >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>> -- >>> >>> Henrique >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181024/3c2e7425/attachment.html>
Hello Scripters,
I really appreciate everything you all have done for the language and have no complaints over here. I do have a suggestion though :)
At work we’ve almost got rid of lodash, except we still need it for DeepCopy vs rolling our own. It’s the same with my side projects. I don’t use lodash because the main times that I need deep copy is when I’m either digging into the Redux store using React, or copying an observable in the Angular world.
I believe ES Script users would appreciate having a deep copy spread operator tremendously.
My proposal is to go off of the current spread operator we currently have in ES and make it 4 dots for a deep spread. This can be used on Objects or Arrays.
‘’’js const oldDeepObj = { InnerObj: { func: () => return ‘wow’ } }
const obj = {....oldDeepObj} obj.innerObj.func = () => return ‘nice’
oldDeepObj.innerObj.func()
Thank you! Looking forward to hearing back from you all. If there’s any other questions let me know