You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If possible in the language of the spec, consider returning an Iterable<MessagePart>? Conforming implementations can still return an array of parts, but some use-cases may benefit from a more lazy approach made possible by the use of generators, for example.
Collecting some of my comments on this here from the original thread, so that it may be closed:
Would that make the error handling potentially weird, though? Let"s say that a user does this:
constsrc="{n is {$n :number minimumFractionDigits=999}}";constmf=newIntl.MessageFormat(src,"en");constparts=mf.formatToParts({n: 42},console.warn);for(letpartofparts)console.log(part);
With array output, it"s pretty clear that the console.warn call will happen before the console.log calls. But with an iterable that"s formatting parts lazily, that might log:
whereas a more eager implementation would report the error earlier.
I think we do want an array. Not because we may want to read its length or access parts by index, but because:
It"s clearer to the caller that onError will never be called after the function has returned a value.
It"s much more user-friendly to allow resetting the position within the parts.
@stasm It would be helpful to have an example or two of use cases which "may benefit from a more lazy approach made possible by the use of generators".
Originally posted by @stasm in #22 (comment)
The text was updated successfully, but these errors were encountered: