How to model a transient state?

115 views
Skip to first unread message

Jacky See

unread,
Oct 18, 2016, 11:11:04 PM10/18/16
to Elm Discuss
Here is a simplified scenario:

type alias Item = { text : String, readState : ReadState, ... }

type ReadState = Read | Unread

type alias Model = { items : List Item }

In the item list view, there is a filter switch: All or Unread.
When the 'Unread' switch is on, it lists all unread items.

Item can be marked as 'Read' by clicking on a item's button,
but then the item immediately disappeared from the filtered list view,
which brings bad user experience.

I'm thinking how should I model such that the just clicked 'unread'
item remains on the filtered list until some other refresh happen?
How to model this 'to be Read' state?

Mark Hamburg

unread,
Oct 18, 2016, 11:16:57 PM10/18/16
to elm-d...@googlegroups.com
If items had identifiers, then I would have some notion of an optional current item in the model or an "except this item" in the filter portion of the model and then have the filter not remove the current item. This can be extended to handle sets of selected items in a natural way. Basically, you want a filter that says "all unread items plus this other item even if it happens to have been read". So, you just need a way to indicate that other item.

Mark


--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jacky See

unread,
Oct 20, 2016, 3:43:59 AM10/20/16
to Elm Discuss
My current approach is to have a `readStateToBe` which contains the pending update state.
and 'flush update' (write `readStateToBe` to `readState`) on appropriate update branch (e.g. switching filter).

Nick H

unread,
Oct 20, 2016, 3:55:36 PM10/20/16
to elm-d...@googlegroups.com
What if you added a third value to the ReadState type?

type ReadState = Read | Unread | Marked

Then your filtered view will show both Unread and Marked. When the user refreshes, you can map all the Marked items to Read.

On Thu, Oct 20, 2016 at 12:43 AM, Jacky See <jack...@gmail.com> wrote:
My current approach is to have a `readStateToBe` which contains the pending update state.
and 'flush update' (write `readStateToBe` to `readState`) on appropriate update branch (e.g. switching filter).

Jacky

unread,
Oct 20, 2016, 5:36:03 PM10/20/16
to elm-d...@googlegroups.com
Thanks! "Marked" is clearer and reflect what's happening on the screen.

--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/r1oWcVL95Fs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Best Regards,
Jacky See
Reply all
Reply to author
Forward
0 new messages