Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Compatibility with Nodejs engine in V8 along with browsers #47099

Closed
ganeshkbhat opened this issue Mar 15, 2023 · 8 comments
Closed

Compatibility with Nodejs engine in V8 along with browsers #47099

ganeshkbhat opened this issue Mar 15, 2023 · 8 comments
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@ganeshkbhat
Copy link

ganeshkbhat commented Mar 15, 2023

What is the problem this feature will solve?

Can I use this MutationObserver on current nodejs version Current? Support V8 Nodejs engine along with browsers.
webmodules/mutation-observer#14 , https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver

What is the feature you are proposing to solve the problem?

Use this MutationObserver on current nodejs version Current? Any polyfill or package will also do.
webmodules/mutation-observer#14 , https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver

What alternatives have you considered?

None. The feature will support Nodejs instead of just browsers. webmodules/mutation-observer#14 , https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver

@ganeshkbhat ganeshkbhat added the feature request Issues that request new features to be added to Node.js. label Mar 15, 2023
@mscdex
Copy link
Contributor

mscdex commented Mar 15, 2023

Node does not have a DOM, so incorporating a MutationObserver doesn't make sense.

@bnoordhuis bnoordhuis closed this as not planned Won't fix, can't repro, duplicate, stale Mar 15, 2023
@targos targos moved this from Pending Triage to Closed in Node.js feature requests Mar 15, 2023
@ganeshkbhat
Copy link
Author

ganeshkbhat commented Mar 28, 2023

True. I am looking at something similar to address the globals which is equivalent of window object in browsers; though not really document or dom

@ganeshkbhat
Copy link
Author

@bnoordhuis @targos would you wish to consider a node.js dom or window MutationObserver implementation alternative in globalThis? Object.observe has been deprecated. Probably, we can take a look back into something that is similar to GC's FinalizationRegistry?

Currently, there is a GC's FinalizationRegistry available for on destroy callback. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry

@targos
Copy link
Member

targos commented Sep 12, 2023

What would you do with a MutationObserver in a Node.js application?

@ganeshkbhat
Copy link
Author

ganeshkbhat commented Sep 12, 2023

Same purpose as GC's FinalizationRegistry on destroy callback but for value declaration, assignation, reassignation, and/ or destruction observers. Probably, you can allow for register and unregister option for the observe callback or assignation/ change observe event handler callback like FinalizationRegistry for informed decision making to avoid memory leaks.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry

1.1: Currently, there is no way I can find the declarations of const's, var's, function's, let's nor the assignation/ change/ destruction of their values. ** [check point 3.1]

1.2: While Object.observe would have been an over-do considering memory leaks this architecture of register/ unregister like in FinalizationRegistry may not be consider we may be using a register, unregister to manage memory leaks.

2.1: Probably, you can just consider register/ unregister events emitters on value assignation/ changes/ destruction in global scope and in specific scope the MutationObserver is assigned to.

Do you wish to re-consider a MutationObserver or an event listener for global or specific scope variables (objects and primitives) alike? I would.

3.1: Raising an alternate feature request for the same #49619 which has an alternative with this https://stackoverflow.com/a/77007865/3204942

@bnoordhuis
Copy link
Member

I don't think MutationObserver does what you think it does. I've commented on the other issue.

@ganeshkbhat
Copy link
Author

ganeshkbhat commented Feb 17, 2024

@bnoordhuis i am sure the MutationObserver is the nearest to Observe a variable change detection. It was implemented in python but seems like a lot of people did not like it.

the problem about javascript is a variable can be a string primitive or string object but need not be a string object always while in python there is consistency. this js inconsistency makes writing a prototype for value change observer difficult. while in python it is much easier. do have a look at this API implementation after there was request made for something like assign here https://github.com/ganeshkbhat/peps/blob/master/pep-9999.rst for python https://peps.python.org/pep-0578/#suggested-audit-hook-locations . This was also scalable for other intents.

how strings work in javascript

>> var s = "string";
undefined
>> var S = String("string")
undefined
>> typeof S
'string'
>> typeof s
'string'
>> var C = new String("string")
undefined
>> typeof C
'object'
>> S instanceof String
false
>> s instanceof String
false
>> C instanceof String
true
>> S instanceof String() // same for s, S, C
VM263:1 Uncaught TypeError: Right-hand side of 'instanceof' is not an object
    at <anonymous>:1:3
(anonymous) @ VM263:1
>> var s = "string";
undefined
>> var S = "string"
undefined
>> var SI = new String("string")
undefined
>> s === S
true
>> s === SI
false
>> S === SI
false
>> SI === new String("string")
false

how strings work in python

s = "string"
print('type of s = "string"', type(s)) 
# type of s = "string" <class 'str'>
S = "string"
print('type of s = "string"', type(S))
# type of s = "string" <class 'str'>
C = str("string")
print('type of s = "string"', type(C))
# type of s = "string" <class 'str'>
s = "string"
print('type of s = "string"', type(s))
S = "string"
print('type of s = "string"', type(S))
C = str("string")
print('type of s = "string"', type(C))
s == S
print('is s == S', s == S)
# is s == S True
s == C
print('is s == C', s == C)
# is s == C True
S == C
print('is S == C', S == C)
# is S == C True

something like this defuncted python project [https://pypi.org/project/assign/](https://pypi.org/project/assign/) but now in a different way like observe for a variable in this [https://pypi.org/project/watchpoints/](https://pypi.org/project/watchpoints/)

@ganeshkbhat
Copy link
Author

ganeshkbhat commented Feb 17, 2024

the observer for assign (equals to = ) for value change may be as powerful as signals. while I believe signal is replica of observe or nodejs MutationObserver in a nicer fashion. cons are memory management due to too many listeners active - a KEY cons for any event system.

while there are listener memory issues on observables, events, observe (which can be put of default disable mode until invoked they have inherent benefits of ensuring value change tracking/ observing.

Do also have a look at this as well https://github.com/ganeshkbhat/peps/blob/master/pep-9999.rst . Probably this calls for a different proposal. but just thinking aloud.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

No branches or pull requests

4 participants