Comments (6)
Another idea would be that if Object.observe is present and the observed value is coming from an accessor, fallback to using dirty checking for just that property. Basically, take a hybrid approach. Use Object.observe for what it can handle, but use dirty checking for everything else. You'd probably want to provide a way to mark an accessor function in the case that you want to handle notifying manually.
This is probably a bigger change in the library, but it would make things work consistently and take the burden off of the developer to write custom code every time they want to use an accessor (which by the way is going to become increasingly common.) I think it's a reasonable compromise.
from observe-js.
The thing is that there is really no reason to use accessors, so there's not a great deal of momentum behind making them work well.
Maybe if you provide a use case (or two) where you want an accessor, we can discuss it and figure out if we have more of a problem than I am suggesting.
The general notion is that instead of creating an accessor which calculates values on demand, one can have a computed property whose value is constructed when the dependent values change.
from observe-js.
The key semantic difference with accessors as computed properties is that their dependencies can be resolved synchronously on access (a-la polymer published attributes).
I agree, it'd be nice to see use cases for exposing a more general form of this, but I can easily imagine it exists.
I suspect it'll make sense to support both patterns (computed data properties vs computed accessor properties) and there will be a familiar expressiveness vs expense tradeoff. Hopefully we can arrive at good syntax and sugaring for both patterns and good docs that correctly outline the trade-offs.
from observe-js.
key semantic difference with accessors as computed properties is that their dependencies can be resolved synchronously on access
True, but this feature is defeated as soon as you try to use your accessor in a data-binding scenario, which is the only time there is actually a problem with accessors. Any data-binding machinery has to query the value of the accessor (and possibly repeatedly when dirty checking).
from observe-js.
Oops, sorry, I responded to a different concept then what you actually wrote, sorry about that.
There is a concept that an accessor can defer processing until the value is queried, that's the bit that is defeated by employing the accessor in a binding context.
With respect to synchronous access, I'm not sure where that's a virtue, since the rest of our system is asynchronous.
(a-la polymer published attributes)
You refer to attribute changes being processed synchronously? This is more of a conceit to folks' expectation of the platform rather than something Polymer actually advocates.
All other data side-effects in Polymer resolve asynchronously (as you of course know =P).
from observe-js.
Sorry again for the noise, my comments above are supposed to be about exploring this topic and not somehow suggesting you (rafaelw) don't have it right. You are the expert in data systems.
from observe-js.
Related Issues (20)
- .set doesnt work with computed bindings, computed properties, or observers
- FTLOG HOT 3
- TypeError: Object.observe is not a function HOT 2
- Build system seems to be broken
- Ability to have performMicrotaskCheckpoint not attached to global
- Use regular expressions instead of state machine HOT 3
- Even faster compiledGetValueFromFn HOT 1
- Is this supposed to work? HOT 3
- Support AMD loading with "define"
- version on npm is 0.4.2 while releases here on github show latest as 0.5.6 HOT 5
- utlise proxy on systems where Proxy is supported HOT 1
- 7 tests broken on latest FF and 6 on Chrome
- Pathobserver on document.title - works in ff, not in chrome
- Supress Object.observe deprecation warning
- IGNORE
- ObjectObserver does not report observed object onChange event
- Chrome 50 breaks this lib HOT 11
- About delivery of changes
- ObjectObserver doesn't seem to work in Safari iOS HOT 3
- Tag with ^1.0.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from observe-js.