fable-compiler / fable-react-native

Fable bindings and helpers for React Native projects
Apache License 2.0
49 stars 11 forks source link

Question about ResizeArrays #31

Closed iyegoroff closed 6 years ago

iyegoroff commented 6 years ago

This project uses only ResizeArray in bindings, e.g.: https://github.com/fable-compiler/fable-react-native/blob/5a9a461d3c825a0c9cd09cc36bbfc50ed841a012/src/Fable.Helpers.ReactNative.fs#L812

So every time you should write something like new ResizeArray<string> ([| "one"; "two"; "three" |]). But it looks like just [| "one"; "two"; "three" |] will generate the same js output.

Is it ok to use ordinary array instead of ResizeArray in bindings?

alfonsogarciacaro commented 6 years ago

It's a bit tricky. In general, Fable uses JS array both for F# ResizeArray and array except for numbers. ts2fable uses ResizeArray by default to avoid this conflict with numbers and also to allow the user to append items if necessary. But I understand sometimes it's more convenient to just use arrays because of the syntax.

In the case of non-numeric arrays and if you're sure it won't be necessary to modify the array's length, it may be OK to change the bindings I guess. BTW, you can save some characters by using ResizeArray [| "one"; "two"; "three" |] instead, or even using an alias or inline operator:

type RA<'T> = ResizeArray<'T>
RA [|"one"; "two"|]
iyegoroff commented 6 years ago

Thank you for the clarification!