-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add "builtAt" to builders #83
Comments
any hope for having this implemented any time soon? :) |
Last I looked at this, it required a lot of boilerplate to make it work--because you have to tell the collection the type of the builder that it needs to expose. It's possible that with Dart 2's type inference this can be workable. I'll take a look again sometime. But probably not very soon ;) ... the next changes for |
Any news on this? |
It's actually possible to do this with extension methods now :) I've been waiting to see how the simpler extension methods (build, toBuiltList, toBuiltSet, toBuiltMap) are received. They seem to have gone smoothly. |
Another enthusiastic dev -- this would clean up a bunch of my code. |
You can actually do this yourself now using extension methods :) I've explored adding them, but didn't get around to a final answer yet. If you try it I'd be interested to hear how it goes :) Something like this:
|
Thanks!
i'm trying to do a rebuildWhere as it would greatly reduce the number of line of code in my async "Bloc" update process (need to get the current index often to avoid edition of the wrong index if list changed). but i don't see how yet. will post back here if find a way. But since ListBuilder doesn't expose indexWhere it won't be easy i think :) |
How about something like
? |
So simple yet working 👍 Thanks!!! |
Hey @davidmorgan , |
@kushvatsa I think this will work extension BuiltValueListBuilderExtension<V extends Built<V, B>,
B extends Builder<V, B>> on ListBuilder<Built<V, B>> {
void rebuildWhere(bool Function(V) test, void Function(B) updates) {
for (var i = 0; i != this.length; ++i) {
if (test(this[i])) this[i] = this[i].rebuild(updates);
}
}
} |
It works @shubhamtanwar23 , Thank you 👍 |
@davidmorgan is there anything preventing one of the above solutions from being merged in? |
@smkhalsa Nothing specific :) I'm a little hesitant about adding extension methods, since they're new, and once they're added it's a breaking API change to change them. Also, it's easy to roll your own :D I'll look at adding these in a coming release. |
How do I use these extension methods? I'm trying to use them but I'm not sure where to add them so that they are recognized. Tried to use it like I use any other extension methods: Creating a file with them and trying to import that file whenever I need to use the methods (like below), but they are not recognized.
In this "rebuildAt" is not recognized as an option. How to use this? |
You're calling
it should be
:) |
ListBuilder could for example have a "builtAt" method that converts the value at the specified index to a builder, similar to the "rebuild" method but for an element in the collection:
var list = new BuiltList<BuiltList>([new BuiltList[1]]);
var rebuiltList = list.rebuild((b) => b.rebuildAt(0).add(2));
--> [[1, 2]]
This should work for nested built collections and for built values.
The text was updated successfully, but these errors were encountered: