Skip to content

Thoughts on mutually recursive hyperviews (Children talking to Parents) #171

@adithyaov

Description

@adithyaov

Thought Experiment:

Parent.hs

data Parent = Parent deriving (ViewId)

class HyperView Parent es where
    data Action Parent = Refresh
    update = do
        ...
        ...
        hyper Child $ ...

Child.hs

data Child = Child deriving (ViewId)

class HyperView Child es where
    data Action Child = UpdateSomething
    update = do
        ...
        ...
        trigger Parent $ Refresh

These are mutually recursive HyperViews.

If I want functionality like the above, I’m forced to keep both Parent and Child in the same module.
This becomes messy if I want to keep Parent and Child in separate modules.

However, this mutual recursion is unnecessary.

  • The update of Parent depends on data Child.
  • The update of Child depends on data Parent and data Action Parent.

The update functions themselves aren’t mutually recursive -
they only appear to be because both Action and update are tied to the same class.

It should be possible to split HyperView into two parts:

class HyperViewDef id es where
  data Action id :: Type
  type Require id :: [Type]
  type Require id = '[]

class HyperViewImpl id es where
  update :: Action id -> Eff (Reader id : es) (View id ())

This split provides much more flexibility in how functionality can be organized.
It also makes conceptual sense to separate definitions and relationships from implementation.

There may be better ways to approach this.
The use case described above represents a very natural way to think about UI structure and how UI elements should communicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions