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

ability to transform a prop into desired state structure? #13

Closed
brainlid opened this issue Dec 30, 2019 · 1 comment
Closed

ability to transform a prop into desired state structure? #13

brainlid opened this issue Dec 30, 2019 · 1 comment

Comments

@brainlid
Copy link
Contributor

A callback to process props/param inputs into the a Surface.LiveComponent's state would be helpful.

The mount/1 callback doesn't have access to the props yet. The render/1 function doesn't feel like the right place.

Here's an example. Let me know if you see a better way to solve this.

<MyOptions item={{ item }} />

An item may look like this:

%{
  name: "Thing",
  options: [{"display text", "value"}]
}

I want to edit the "options" value. I need to transform it into a structure I can work with more easily. Additionally, it would be helpful if it had an ID for handling edits and deletes. The ID can be generated using Ecto.UUID.generate(). The desired structure might look like this...

%{
  id: "c9215b61-e5af-410a-a84e-fa4195931eb6",
  display: "display text",
  value: "value"
}

There currently doesn't appear to be a good place to perform this transformation from a prop value into the state I want to manage internally.

@brainlid
Copy link
Contributor Author

Nevermind. The update/2 callback is there and works well for this. It just isn't in the docs (website) that I was looking at. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant