-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ObservableArray should have public member .array #266
Comments
Please clarify. Are you proposing to add this? get array() { return this.getArray(); } |
The proposal is that: this._array = []; // @private internal, do not access directly would change to // @public (read-only) - the underlying array
this.array = []; |
I think that's a very dangerous direction, as is a getter. It's too easy to accidentally modify the "underlying array" and introduce subtle bugs. It also breaks encapsulation by exposing the implementation of how values are stored inside ObservableArray. |
How would you characterize the existing implementation, which is |
I try to avoid using |
For sims that are using electrons.array or electrons.getArray() What pattern do you recommend when a sim needs to listen for when items are added or removed? |
Ideally, I'd like The current API for listening for items added/removed seems fine. Concerns about that part of the API in #5 seem to have been addressed. |
... and i the context of my previous comment, I don't care for |
How would you feel if we change For cases that need maximum performance, should they be able to access the underlying array? Or will they be discouraged from using ObservableArary in the first place? |
That would be fine with me. I've never used either, and it seems like returning an Array would be more useful.
In cases where performance needs to be maximized, I would avoid using |
I improved documentation in the commits. I noticed there are 86 occurrences of return _.find( this.masses.getArray(), mass => mass.isBoat() ) || null; But this could likely be changed to something like: return this.masses.find( mass => mass.isBoat() ) || null; I'm not sure who should work on this or when it should be done, but we have strayed from the intent of this issue so I'll open a new one. @pixelzoom can this issue be closed? |
Seems appropriate to close. |
To enhance usability, ObservableArray should have a public member .array. Discovered during #265
The text was updated successfully, but these errors were encountered: