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

Add receiver to typeaheads and dropdowns #79

Open
davezuch opened this issue Mar 8, 2019 · 4 comments
Open

Add receiver to typeaheads and dropdowns #79

davezuch opened this issue Mar 8, 2019 · 4 comments

Comments

@davezuch
Copy link
Member

davezuch commented Mar 8, 2019

Environment

  • Ocelot [v0.14.5]

Current behavior

Currently you can set the initial items for a dropdown or typeahead via either the parent's render function, or the parent's eval by sending the child component the appropriate query. However, the only way to update the items for a dropdown or typeahead is from the parent eval via a child query.

Expected behavior

There are two scenarios for managing the items for a component:

1. letting the child fully manage them

In this scenario, the parent fetches the items once and passes them to the child, or provides the child a function for fetching them itself—as with an async typeahead. In this scenario, the parent needn't ever hold on to the items in its own state. This scenario is currently supported by Ocelot.

2. the parent manages the items

In this scenario, the parent has reason to deal with the items and hold onto them in state, and the child should be able to basically use the items that are managed on the parent state. This scenario is only partially supported, and requires manually updating the child's items.

Currently, the items on the parent's state can be passed to a dropdown like so:

HH.slot unit Dropdown.componont
  { items: state.items
  , selectedItem: state.selectedItem
  , render: renderDropdown
  }

But then when state.items changes, the dropdown component won't be notified. If we update the typeahead and dropdown components with a receiver, we can respond to changes in input from the parent.

joneshf-cn added a commit to citizennet/purescript-lynx that referenced this issue Mar 9, 2019
We have to do this manually in order to address:
citizennet/purescript-ocelot#79.
The changes here allow the `options` to actually be dynamic.

Unfortunately, we have to remove the tests on the queries because of that.
There's no easy way to evaluate a `HalogenM _ _ _ _ _ _ _`.

Maybe someone will release an easy way to do this in the future,
and we can use that.
Until then, we're testless for our `eval`.
@thomashoneyman
Copy link
Collaborator

@davezuch Remember when we had a flag for this, called receive or listen or something like that? That way you could decide which behavior you want. If you want the child component to defer management to the parent component, then you'd set listen: true and that would enable the receiver. If not, then you'd set listen: false and that would disable the receiver (and be the current behavior).

@davezuch
Copy link
Member Author

@thomashoneyman I don't recall. We got rid of this though? I was thinking on this more, and I don't think we can support both styles at the same time (without some conditional receiver like you mention), since in the case where we want to have the child manage its items, every time the parent state changes, the child's items will be reset to NotAsked (or whatever initial value is passed via the parent's render).

@thomashoneyman
Copy link
Collaborator

@davezuch I implemented it in a branch, but we didn't end up needing it, so we never merged it. It ended up being something like:

type Input = { listen :: Boolean, ... }

data Query a = Receive Input a

component = H.component { receiver: Just <<< Receive, ... }
  where
  eval = case _ of
    Receive input a -> do
      when input.listen do
        H.modify_ _ { items = input.items }
      pure a

so that the receiver query is always run, but it only sets its items to the parent's items when it is listening, and if it is not listening, then it preserves its own items without overwriting them with new input

@davezuch
Copy link
Member Author

@thomashoneyman that seems like a good solution, I might just use it. Thanks!

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

2 participants