Immutability and observability
Opened this issue · 0 comments
benlieb commented
I've only played with spraypaint for a day now, but it is nearly everything I wanted in client-side modeling. Great library.
Since I do a lot of react-style UIs though, it would be really wonderful if this lib added observability (when attrs change) and immutability (as in immutable.js). That would make the circle complete for me.
So I guess this is a feature request.
Currently trying to figure out how to patch into the EventBus like I see in the source for observability:
EventBus.addEventListener(this.storeKey, this.onStoreChange())
But not successfully.
I've also implemented a super simple POC for making attr changes, but it's far from ideal:
const ApplicationRecord = SpraypaintBase.extend(
{
static: {
baseUrl: window.location.origin,
apiNamespace: "/api"
},
methods: {
set: function(prop, val) {
this[prop] = val
this.notifyListeners()
},
notifyListeners: function() {
console.log('notifying');
this.changeListeners ||= []
this.changeListeners.forEach(
listener => listener(this)
)
},
registerListener: function(listener) {
this.changeListeners ||= []
this.changeListeners.push(listener)
},
}
}
)