Thoughts on JFX Flow Places?

17 views
Skip to first unread message

Daniel Zwolenski

unread,
Feb 9, 2012, 8:06:44 AM2/9/12
to jfxflow...@googlegroups.com
Hey guys, 

I am after some thoughts and feedback on how JFX Flow does 'Places'. I toyed with two models when first designing Flow. 

The first is what you see in there now, where a Place is effectively a String place name and a Map of simple, named parameters. When a Place is navigated to, the place name is used to look up the activity and the param names are mapped to @Param variables on the Activity. In this approach we do something like the following: 

navigationManager.goTo(new PlaceBuilder("person")
    .parameter("personId", id)
    .parameter("isAdmin", false)
    .build());

And the activity has: 

class PersonActivity implements Activity
{
    @Param private long personId;
    @Param private boolean isAdmin;

    public void activate() {...} 
}


The second option was to make each Place in the system be defined as a type safe object with proper typed variables on it. When a Place is navigated to, the class of the Place is used to find the matching Activity for it and then the activity is passed the entire Place object when it is activated. in this approach we end up with something like the following: 

    navigationManager.goTo(new PersonPlace(id, false));

And the activity would have:

class PersonActivity implements Activity<PersonPlace>
 
{
    public void activate(PersonPlace place) {...} 
}

And the place class would be:

class PersonPlace 
{
    private long personId;
    private boolean isAdmin;

    ... constructors, getters, and setters ...
}


I quite liked the second approach as it resulted in very tight, type-safe Place classes. The drawback however was that for every activity you'd have to now create a new Place class instance. I felt people might consider that a bit of bloat so I shied away from it. There were also some complexities with generics and sub-Activities, but I would need to play around with it again to work out what these were and probably there are ways to sort them out. 

In using the framework on my own project, I hit a few things that make me wonder whether a type safe Place might be a better option:

1. Managing strings is always more error prone than managing type safe classes and variables. In the type safe approach, the compiler tells me when things don't match up. 

2. I found I needed to get hold of the current place so I could edit it (e.g. the current place is now showing search results from 30 to 40), then when the back button or refresh button caused a reload of the page it would maintain its state. I could edit current variables, but that doesn't change the place if back/refresh is selected. I could expose the Place object and then change the parameter map, but it gets messy with those strings, and now we have two places for the variable - the map and the @Param variable. If we just pass in the type safe PersonPlace to the activity itself it becomes easy.

3. I found I wanted to clear parameters when navigating to a Place. In the Map approach I couldn't really say 'isAdmin' should be null, the current implementation will just leave this variable set to whatever was last loaded if it is not in the map. I could make Flow clear any variable marked with @Param that is not present in the current place's parameter map but then there may be situations where you don't want to clear it. A full, typed Place object would solve this problem cleanly.

4. In some cases I wanted to have sub-activities that were not activated via the NavManager, etc. In the current setup I had to expose setters for the params and manually set and activate the Activity. If I had a simple activate(Place) method on the Activity then it would be a simple case to activate the Activity with its parameters without needing all the supporting NavManager classes, etc. This would also make it easier to unit test. 


So I am wondering what you guys think. Does the current approach work for you, would you like/hate it if Flow was changed to use type safe Place's so you would then have to declare a Place class for every Activity you create (even if there are no parameters for it), can you see any problems with either approach, or have any better suggestions? 

I'm also concious of the fact that a few of you are actually using the alpha version of Flow in some applications so I'd also like to know changes like this will cause you grief and I should limit changes, or whether people are quite happy just to make changes in their code as I release new updates. Easiest for me is to just push out more snapshots, but if needs be I can have more controlled version management and push an official build into Maven before I make changes to the APi?

Cheers for your input,
Dan  
Reply all
Reply to author
Forward
0 new messages