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

Recognise that view isn't in the hierarchy with flow.has #210

Open
dariocravero opened this issue Apr 13, 2021 · 0 comments
Open

Recognise that view isn't in the hierarchy with flow.has #210

dariocravero opened this issue Apr 13, 2021 · 0 comments

Comments

@dariocravero
Copy link

dariocravero commented Apr 13, 2021

In this app flowhasissue.zip, when /App/Content is No, then the button on /App/EditOneAction shouldn't have isSelected set to true because /App/Content/Content/Edit/One isn't set.

What happens now is that because One is the default view in /App/Content/Content/Edit, it wins because of this https://github.com/viewstools/morph/blob/master/views/ViewsFlow.js#L104.

The expected behaviour would be that the flow.has method goes all the way up trying to find whether a parent of the view being checked is in fact in the flow, be it that it is a default view of an active path or not.

A workaround for now is to add a new view called No in /App/Content/Content/Edit.

Side note:
Since that'll be a recursive operation, it might be slow. Since these checks happen on every render I suggest that whenever we implement this we also consider adding a local cache to flow.has, something like this:

export function useFlow() {
  let state = useFlowState()

  return useMemo(() => {
    let _has = {}

    return {
      has: key => {
        if (!key) return false

        if (!(key in _has)) {
          _has[key] = calculate()
        }
        return _has[key]

        function calculate() {
          // ...the actual logic we have in there now plus the changes
        }
      },
      flow: state.flow,
    }
  }, [state.flow])
}

This will need to be tested for side effects with flow items with arguments (eg, a list gets a new item or the item gets removed) but in principle it should work as-is.

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