Name-spaced cross-realm objects
# Isiah Meadows (6 years ago)
Not a huge fan. This explicit encapsulation break could be done via an explicit bootstrapper that can send values across realms, and scenarios on the same realm can just use global state. Also, the utility seems a bit low IMHO.
Not a huge fan. This explicit encapsulation break could be done via an explicit bootstrapper that can send values across realms, and scenarios on the same realm can just use global state. Also, the utility seems a bit low IMHO. On Tue, Mar 12, 2019 at 00:39 Sultan <thysultan at gmail.com> wrote: > The following is currently possible with setTimeout from the browser > > const i = setTimeout(() => {}) > > Where "i" is a number from 0 incrementing towards infinity. > > This however has the issue that it is entirely global, and as the title of > the post suggests the idea is to strike a middle ground between global and > name-spaced; That is the ability to create/access your own name-spaced > state similar to Symbol.for. As an example – a name-spaced incrementing > number: > > // a.js > const fn = UID.for('namespace') > > assert(fn() === 0) > assert(fn() === 1) > > // b.js > > const fn = UID.for('namespace') > > assert(fn() === 2) > assert(fn() === 3) > > This however would be implemented in user-land on top of a more general > proposal for creating cross realm name-spaced objects: > > // a.js > const obj = Object.for('namespace') > > // b.js > const obj = Object.for('namespace') > > Where both objects "obj" in the files a.js and b.js would point to the > same object. > > Disclaimer: I'm aware all of the above can be implemented with global > state if you disregard the cross-realm requirement. > _______________________________________________ > 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/20190312/4a7db9ce/attachment-0001.html>
The following is currently possible with setTimeout from the browser
const i = setTimeout(() => {})
Where "i" is a number from 0 incrementing towards infinity.
This however has the issue that it is entirely global, and as the title of the post suggests the idea is to strike a middle ground between global and name-spaced; That is the ability to create/access your own name-spaced state similar to Symbol.for. As an example – a name-spaced incrementing number:
// a.js const fn = UID.for('namespace')
assert(fn() === 0) assert(fn() === 1)
// b.js
const fn = UID.for('namespace')
assert(fn() === 2) assert(fn() === 3)
This however would be implemented in user-land on top of a more general proposal for creating cross realm name-spaced objects:
// a.js const obj = Object.for('namespace')
// b.js const obj = Object.for('namespace')
Where both objects "obj" in the files a.js and b.js would point to the same object.
Disclaimer: I'm aware all of the above can be implemented with global state if you disregard the cross-realm requirement.