@stukalin wrote:
I am in the process of migration to Octane and I face a problem I used to solve in the pre-octane versions with a simple hack, but now I am a bit confused. Here it is.
Say, I’ve got a model
// it's not migrated yet, nevermind export default DS.Model.extend({ someObject: DS.attr(), anotherobjects: DS.hasMany('anotherObject', {async: false}), }
then in my component I allow editing of this
someObject
but I don’t want it to be bound tomyModel
but rather be detached. I do this using a so-called buffer, so the component works with this buffer and when it comes to save it simply rewrites the original model property and saves. However there is a single situation when I want my buffer to be recalculated, namely when the array ofanotherobjects
is changed. So, everything look somewhat like thisbuffer: computed('{myModel.anotherobjects.[]}', function () { return {...this.myModel.someObject}; }), persist: task(function* () { // Copy the buffer back to the model and save it let bufferClone ={...this.buffer}; this.myModel.set('someObject', bufferClone); yield this.myModel.save(); }).restartable()
Phew, that was a long intro. Anyways, the hack I have here is that I don’t explicitly put the
someObject
as mybuffer
computed dependency, so it’s calculated only once (or in that rare case whenanotherobjects
array changes).Now the questions:
- How can I do the same thing in octane? i.e. is it possible to tell exactly which properties I want to track and which I don’t wanna track.
// If I simply declared it as getter I'd have 2 issues: // I'll bound it to the `myModel.someObject` and vice versa //I won't have any mention of `myModel.anotherobjects` get buffer() { return {...this.myModel.someObject}; }
- There is still the
@computed
decorator. From the documentation it’s not clear which status it has in the octane world: will it be deprecated? And what would happen if I put it on a getter: will it disable the tracked stuff at all, i.e. would this code be equivalent to my old one?// will this work as expected? @computed('{myModel.anotherobjects.[]}') get buffer() { return {...this.myModel.someObject}; }
- (probably the most important one) Are there any other techniques to achieve the same goal I am trying to achieve?
Posts: 1
Participants: 1