doridori / Pilot

An android.* decoupled application stack for Android
Apache License 2.0
116 stars 9 forks source link

PilotStack operations Builder object #36

Open doridori opened 8 years ago

doridori commented 8 years ago

Keep coming across scenarios where being able to execute stack operations / transactions atomically would be nice. These fall into

single listener callback for group operations

Problem here is that if you addFrame then removeFrame the logic can get a bit annoying to work out if should notify listeners for both actions. Dont really want every stack op method to have a 'notifyListeners' param.

Also helps for notifying a was visible top of stack frame now not vis without duplicates

not nullifiing the parent stack for the next operation

Easy to accidtally do something like getParentStack.clearStack getParentStack.pushFrame which throws an NPE on second call

understanding what txns are grouped would make stack txn logging easier

When looking at showing readable logging #33 for stack state and stack txns would be easier if the txn groups were atomic then could show StackState -> startTxn -> Ops -> endTxn -> StackState

not accidentally closing app

Sometimes the stack can be empty for a short time between transactions, which currently triggers a stackEmpty callback which pretty much always closes the app (which you would want if result of back presses). atomic txns would not let this happen!

Could look something like

getStack().startTxn()
.popTo(FrameName.class, INCLUSIVE)
.pushFrame(DataFrame.class, Args)
.pushFrame(TopFrame.class)
.notifyListeners(true) //default
.go();
doridori commented 7 years ago

Flow / flowless do this e.g.

Flow.get(this).setHistory(history.buildUpon().pop(2).push(SomeKey.create()).build(), Direction.BACKWARD);

see https://github.com/Zhuinden/flowless/blob/master/README.md