Skip to content

feat: update API to allow optional parameters #33

@alestiago

Description

@alestiago

Description

From flame, one can instantiate a component as follows:

 textComponent = TextComponent(
    text: counter.toString(),
    textRenderer: _textPaint,
  );

See implementation here.

For consistency, perhaps it would be nice to update forge2d API to also support this pattern. For example, with shapes. We could:

final shape = CircleShape(radius: radius);

instead of

final shape = CircleShape()
  ..radius = radius;

Additional Context
Personally, both can be seen as equivalent. I think both APIs should be supported (cascading and optional parameters). Besides consistency with flame, one could also argue that using the positional parameter avoids setting/changing the value first unnecessary, since we already know its computed value and will change instantly after.

In addition, we also benefit from the analyser when we are setting default values.

This issue is open to discussion. If we decide to proceed I'm willing to contribute with this update.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions