-
Notifications
You must be signed in to change notification settings - Fork 301
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
ListCollector #3745
ListCollector #3745
Conversation
This is probably because you used This tells Fable attach members to the JavaScript class instead of generated a function outside of the type like With import { class_type } from "fable-library/Reflection.js";
export class ListCollector$1 {
constructor() {
this.collector = [];
}
Add(value) {
const this$ = this;
void (this$.collector.push(value));
}
}
export function ListCollector$1_$reflection(gen0) {
return class_type("Test.ListCollector`1", [gen0], ListCollector$1);
}
export function ListCollector$1_$ctor() {
return new ListCollector$1();
} Without import { class_type } from "fable-library/Reflection.js";
export class ListCollector$1 {
constructor() {
this.collector = [];
}
}
export function ListCollector$1_$reflection(gen0) {
return class_type("Test.ListCollector`1", [gen0], ListCollector$1);
}
export function ListCollector$1_$ctor() {
return new ListCollector$1();
}
export function ListCollector$1__Add_2B595(this$, value) {
void (this$.collector.push(value));
} If you remove In general The alternative would be to specifically rewrite how Fable generates the code for this type/members. For info using |
Removing those attributes doesn't help that much. |
Fixed ListCollector constructor
Thanks again @ncave for fixing this! |
tests/Js/Main/ListCollectorTests.fs
Outdated
let tests = | ||
testList "ListCollector" [ | ||
testCase "ListCollector.Add and .Close" <| fun () -> | ||
let result = cutOffLast [ 1; 2; 3 ] | ||
result |> equal [ 1; 2 ] | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add tests for each method
available and also edges cases like calling .close()
on an empty ListCollector
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not overextend. I'm including only the parts that interest me, as this is largely experimental. The code is already solid—something we're both aware of—and this pull request improves its current state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree yes for this module it is probably enough, but it happens several times that doing so allowed us to catch behaviour we were not aware of.
There are still some APIs in fable-library that don't behave correctly because they didn't have a test associated for every usage. Having tests also allows us to catch on regressions.
I added the tests to cover the most common cases.
open Microsoft.FSharp.Core.CompilerServices | ||
|
||
let cutOffLast list = | ||
let mutable headList = ListCollector<'a>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the code it seems like we can remove the mutable
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would not reflect the actual usage of shared code. In regular F# the collector needs to be mutable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know about that.
Thanks for the implementation, I will include it in the next release which should come out this weekend. |
Thanks for going the extra mile here! |
An initial naive implementation for #3700.
I'm a little confused that
FSharp.Core.CompilerServices.js
looks fine:but the usage in
QuickTest.js
does not:Am I missing something obvious @MangelMaxime @ncave?