bigab / observable-objects Goto Github PK
View Code? Open in Web Editor NEWCreate objects and subscribe to property changes on the object
License: MIT License
Create objects and subscribe to property changes on the object
License: MIT License
The target
property emitted in the event should not allow mutation.
I think the best option is for target to be a proxy to the source, with a proxy tree just like the actual observable proxy, except that all set
's get trapped and no-op (or warn)
When a child object or array has a property changed, the observable should emit an event with the appropriate path
value of the change
Like in CanJS should you be able to do something like:
@observable
class MyThing {
userAccount = UserAccount.getActiveUser(),
get fullname() {
return `${this.userAccount.firstName} ${this.userAccount.lastName}`
}
}
const thing = new MyThing();
Observable.of(thing).subscribe({
next(e){ console.log(e.target.fullname) }
});
console.log( thing.fullname ) // Logs: Adam Barrett
const activeUser = UserAccount.getActiveUser();
activeUser.firstName = 'Isla' // Logs: Isla Barrett
...where instances of UserAccount
are also observables, and so any change to them will actually end up triggering a change in the thing
instance because of the "derived" or "computed" property?
If so, would it also be a good Idea to implement a @lazy
decorator for such accessor properties so that that we could cache the last value, and only update that value when an internal observable emits a 'relevant' change.
@observable
class MyThing {
userAccount = UserAccount.getActiveUser(),
@lazy
get fullname() {
return `${this.userAccount.firstName} ${this.userAccount.lastName}`
}
}
I think it would be a good idea, but it sounds like a lot of work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.