-
Notifications
You must be signed in to change notification settings - Fork 6
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
Changes to ReactiveArray #22
Comments
Is there a reason you'd want to have a sort and reverse method that can be mutable? Why not just Though i'm slightly confused by:
with:
Aren't these contradicting? The proposal adds those methods that make the values mutable, yet you also don't want a mutating version built into destiny? Though maybe it isn't as simple as "oh ReactiveArray just inherits sort" due to Reactivity (I'm aware i'm not fully 100% understanding of how these things are build within destiny) In terms of methods you supply that aren't present on native arrays, maybe it's an idea to only provide non-native methods that are specific to destiny, for example, |
ReactiveArray doesn't directly extend Array at all. Most methods are reimplemented for the class to mimic the native methods as closely as feasible. However, some methods that are completely infeasible to be reimplemented access the underlying array, call the method on it, and then rewrites all the current values with whatever the native one returns with: reverse (): this {
this.value = this.value.reverse();
return this;
} Note that setting set value (
items: ReadonlyArray<InputType | TArrayValueType<InputType>>,
) {
this.#splice(
0,
this.#value.length,
...items,
);
}
You're right about
|
reverse
andsort
don't make a whole lot of sense as mutable methods onReactiveArray
s, and it would make more sense for them to return new arrays instead. With that in mind, I plan to add the following methods from the change Array by copy proposal:withReversed
withSorted
…and remove
reverse
andsort
. If someone needs the mutating version, they could simply doarr.value = arr.value.reverse()
for example.Additionally, there are some other methods on native Arrays that don't make a whole lot of sense for ReactiveArrays with correct usage of the library, or are impossible to have their updates be optimized. With that in mind, I plan to remove
flat
,flatMap
,copyWithin
, andfill
.concat
is somewhat useful, but the semantics of nativeArray.prototype.concat()
are quite convoluted, and I would much rather have a simple function that does nothing but concatenateReactiveArray
s. I don't know if it would make more sense to changeconcat
to have semantics that are not in line with the native equivalent, or to removeconcat
and make a new function with simpler semantics to avoid confusion.Finally, it seems like the mutating methods proposed and discussed in #4 haven't been very popular, and similar functionality could be achieved with similar effort using a
for
loop, so I plan to remove the ones implemented:mutFilter
andmutMap
.Click for a list of `ReactiveArray` methods
On ReadonlyReactiveArray:
bind
❇clone
❇concat
🚮?enties
every
exclusiveSome
❇filter
find
findIndex
flat
🚮flatMap
🚮forEach
get
includes
indexOf
join
keys
lastIndexOf
map
pipe
❇reduce
reduceRight
slice
some
toJSON
unbind
❇update
❇values
withReversed
🆕withSorted
🆕On ReactiveArray:
copyWithin
🚮fill
🚮mutFilter
❇🚮mutMap
❇🚮pop
push
reverse
🚮set
❇shift
sort
🚮splice
unshift
🆕 = proposed addition
❇ = not present on native Arrays
🚮 = planned for removal
Thoughts?
The text was updated successfully, but these errors were encountered: