Skip to content
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

Custom parameter type’s encode function is not called for array params #37

Closed
rluba opened this issue Feb 10, 2017 · 2 comments
Closed

Comments

@rluba
Copy link

rluba commented Feb 10, 2017

The problem

  1. Define a custom type using the definitionFn instead of the definition object
  2. Use this new type for a state parameter that does not explicitly set array: false
  3. The parameter type’s encode function is never invoked during state transitions, so the parameter is not encoded correctly.

The reason
Because the parameter does not declare array: false its type is wrapped into an ArrayType during state declaration – that’s before the type’s definitionFn is invoked.

But ArrayType defines its encode function (and others) based on the wrapped type’s functions at the time when ArrayType is instantiated. ArrayType stores a reference to the old encode function (which was undefined, so it’s the identity function) instead of looking up the actual function when ArrayType.encode is called.

Later, the type’s definitionFn is invoked and redefines the encode function, but the array params still reference the identity function.

The solution

  • Either defer the instantiation of ArrayType until after all definitionFns were invoked (probably compilcated)
  • Or define the ArrayType’s functions based on the run-time value of the wrapped type’s functions instead of capturing them locally.
@christopherthielen christopherthielen added this to the 5.3.0 milestone Feb 23, 2017
@christopherthielen
Copy link
Member

I appreciate the detailed bug report!

@christopherthielen christopherthielen removed this from the 5.3.0 milestone Jun 14, 2019
@stale
Copy link

stale bot commented Jan 24, 2020

This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues
may be reopened.

Thank you for your contributions.

@stale stale bot added the stale label Jan 24, 2020
@stale stale bot closed this as completed Feb 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants