@Override
public void onCreate() {
super.onCreate();
App.instance = this;
PersistanceController persistanceController = new PersistanceController(this);
State initialState = persistanceController.getSavedState();
if (initialState == null) {
initialState = State.Default.build();
}
this.store = new Store<>(new State.Reducer(),
initialState,
new Logger<>("Talalarmo"),
persistanceController,
new AlarmController(this));
this.store.subscribe(Anvil::render);
}
public void onCreate(Bundle b) {
super.onCreate(b);
store = new Store<>(this::reduce, // reducer function
new State(0), // initial state
new Logger("Counter")); // Middleware: logger
setContentView(new RenderableView(this) {
public void view() {
linearLayout(() -> {
orientation(LinearLayout.VERTICAL);
// Bind count value to a text view
textView(() -> {
size(FILL, WRAP);
text("Count: " + store.getState().count);
});
// Bind actions
button(() -> {
size(FILL, WRAP);
text("+1");
// Action without arguments
onClick(v -> store.dispatch(new Action<>(CounterAction.INCREMENT)));
});
button(() -> {
size(FILL, WRAP);
text("+10");
// Action with arguments
onClick(v -> store.dispatch(new Action<>(CounterAction.PLUS, 10)));
});
});
}
});
}