dotanuki-labs/norris

Code readability

dbof10 opened this issue · 6 comments

hi I know you've moved to processor recently

 when (interaction) {
            is QueryDefined -> {
                processor.process(
                    CommandTrigger(::save, interaction)
                )
            }
            else -> {
                interpret(interaction)
                    .let { transition ->
                        machine.consume(transition)
                    }
            }
        }

your impl is quite hard to understand. with QueryDefined you use processor, else you use machine.consume(transition). what are the reasons behind?

your impl is quite hard to understand

@dbof10 I quite disagree : the implementation is straightforward. It says

When the interaction reports that user defined a query, trigger a command; otherwise, interpret the interaction, once it will generate a new ViewState

The reason behind separation between StateMachine and CommandsProcessor is : the first one broadcasts states, the second one commands (both consumed at the View level). Commands are intended to be handled at the View level without any changes on the current state; therefore, they are used (in the current implementation) to dispatch a navigation command to the View.

I'm evaluating to unify both StateMachine and CommandsProcessor under a single abstraction and let the interpretation of the incoming "events" to be handled at the View level (therefore, the when statement above would have a mirror in the View)

So in which case, I will use processor which case I let the machine consume the interaction?
Another issue with this arch is how can I get current viewstate at a given time?

So in which case, I will use processor which case I let the machine consume the interaction?

As I wrote above : commands (as far I see) don't change the UI state. Only states changes the UI state. Navigation is one usage for commands; other side effects are possible to fit in such design.

Another issue with this arch is how can I get current viewstate at a given time?

Sorry, why is this an "issue"?

And last, but not least : what is the use case for retrieving a particular ViewState?

  1. Given I fetch a product from api, then I show it. When I click share, I need to create an intent with an image url in the product. This is the use case
  2. I just found out that this arch has a bug. Given a Activity with a fragment A with APresentation class, when I navigate to fragment B with BPresentation class from fragment A within the same Activity. It re-emits state from fragmentA to fragment B leading to ClassCastException
lcszc commented

Given I fetch a product from api, then I show it. When I click share, I need to create an intent with an image url in the product.

I think you can use the processor to trigger a command so the View can create the Intent. But you can also do it in the default way: View listen to OnClick event and then creates the Intent,

Check out FactsAdapter.

I just found out that this arch has a bug. Given a Activity with a fragment A with APresentation class, when I navigate to fragment B with BPresentation class from fragment A within the same Activity. It re-emits state from fragmentA to fragment B leading to ClassCastException

This project doesn't uses Fragment, mate. I've been testing it for a while and didn't found any problem within its navigation.

If you have changed its View to use Fragment instead maybe you did something wrong.