Instances of global classes not observable
See original GitHub issueTest case:
https://runkit.com/scriptspry/observer-utils-global-definitions-not-observable
const {observable, observe, isObservable} = require('@nx-js/observer-util');
class Counter {
constructor() { this._count = 0 }
increment() { this._count += 1 }
decrement() { this._count -= 1 }
}
const c = observable(new Counter());
console.log('c', isObservable(c));
global.Counter = Counter;
const c2 = observable(new Counter());
console.log('c2', isObservable(c2));
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
'Observable<T>' is not a class derived from 'Observable<T>'
I just came across a very similar issue while developing a custom module for a project. I'm not 100% sure we were having...
Read more >Custom decorator with observable not update component #2155
Hi. I try to create custom decorator which add some functionality to my class. Values are changed. In var this.inputsState there is proxy ......
Read more >Observables compared to other techniques - Angular
Observable subscriptions are cancellable. Unsubscribing removes the listener from receiving further values, and notifies the subscriber function to cancel work.
Read more >Managing model data in your app - Apple Developer
To update views when data changes, you make your data model classes observable objects, publish their properties, and declare instances of them using ......
Read more >ObservableProperty attribute - .NET Community Toolkit
The ObservableProperty type is an attribute that allows generating observable properties from annotated fields. Its purpose is to greatly ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi!
That’s intended, but it is a dirty hack and it should be changed. I introduced this in the latest patch (4.1.2). The reason:
Built-in JS objects can not be wrapped with Proxies because of their ‘internal slots’. They throw an ‘Invalid Invocation’ error when you try to call their methods on the wrapping Proxy. To work around this I had to do two things.
To do the latter I need an algorithm, which detects built-in Objects. At first I tried to maintain a list, since there or not so many standard JS built-ins. I failed to do this though, because this lib supports both NodeJS and browsers, which have a lot of different built-ins. I got issues about illegal invocation error on WebAudio objects (browser built-in) for example. Maintaining a list of all browser and NodeJS built-ins is not feasible, so I decided to do the current dirty detection. I check if the object constructor is available on the global Object, since all built-ins are global.
This should swapped with a more elegant algorithm, but I couldn’t find any. I will keep thinking about this and change it soon and I am open to any suggestions, ideas and PRs.
I hope this made the issue clear. Thanks for the issues 🙂 (I won’t be around during the weekend.)
On second thought, I don’t think that will work, It will just check for things in Window but not things like Map, Array etc. which are what need to be skipped. I have no other ideas. Perhaps posting on stackoverflow may help us.
EDIT: posted too soon. I think this might still work. Object.keys(frame.contentWindow) didn’t have Map, Array etc. but ‘Array’ in frame.contentWindow is true. So that might just work.