Skip to content

Should we allow setState() separate from update()? #57

Closed
@domenic

Description

@domenic

Continuing from @tbondwilkinson's comment at #54 (comment):

I'm not sure about setState().

I think it creates the same problem that we have today with history.pushState() where it's updating the browser about the current state of things AFTER that state has been changed. So on the one hand we're encouraging people to do navigations by storing information in history and responding to those data changes in the navigate event, but this new setState() method is an out - it basically means that there's a workaround to update things in history without ever triggering a navigate event (where we would expect most people's rendering code to be). I think that dilutes the model and is pretty niche.

I'm sympathetic to these concerns. I think the crucial question is whether we consider a no-URL-update change to the state to be a navigation, or not.

In particular, the discussions in #42 (comment) indicated to me that maybe state-but-not-URL updates are conceptually different. E.g., they would be used for syncing state from the DOM to the state object, and it'd be strange for them to be considered navigations. The design in the explainer after #54 makes it so that update() always causes a full navigation by default, which the app would intercept with navigate. It then expects you to use setState() for other cases.

I may have jumped the gun here though in assuming they are different. If we think that an app will generally want to treat no-URL-update state changes as navigations on the same level as URL-update ones, then we should get rid of setState() and force everything through update().

Further, it means that some part of the application can just clear your state and you don't get any event about it besides currentchange. That also feels bad.

A late-breaking addition to #54 was the statechange event, so you get that. And to be clear, you don't get currentchange as formulated. Whether currentchange fires or not is tied to a few questions:

Metadata

Metadata

Assignees

No one assigned

    Labels

    changeA proposed change to the API, not foundational, but deeper than the surface

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions