How to use Behavior Delegate?

Hi, I am kinda of a noob and I haven't really found anything with an example of what I am trying to do. Also, I am not sure I really understand the flow yet, but here is the example.

Basically I am trying to use a behavioral delegate to toggle all the data on my View. I am not sure how to refresh the View. I feel like I am missing something simple. It wont let me call any functions in the view or doesn't let me update any variable in the view or the appbase.

Any advice would be greatly appreciated.

AppBase:

function getInitialView() {

...
return [_view, new ForecastLineDelegate(_view)];

-----------

BehaviorDelegate:

class ForecastLineDelegate extends WatchUi.BehaviorDelegate {

function onSelect() {

switchPage();
return true;
}

function switchPage() {

var page = App.Storage.getValue(ForecastLine.PAGE);
if (page == 1) {
App.Storage.setValue(ForecastLine.PAGE,2);
}else{
App.Storage.setValue(ForecastLine.PAGE,1);
}
return true;
}

  • WatchUi.requestUpdate();

    Not sure why you're using storage to pass things around.  You're hitting the file system a more than needed.

    You already pass the view to the delegate, so why just use class variables in the view?

  • class MyView extends Ui.View {
      var page1=true;
    ...
      function onUpdate(dc) {
        if(page1) {
    ...
        } else {
    ...
        }
      }
    }
    
    class ForecastLineDelegate extends WatchUi.BehaviorDelegate {
      var view;
    
      function initialize(v) {
        BehaviorDelegate.initialize();
        view=v;
      }
    
      function onSelect() {
        view.page1=!view.page1;
        WatchUi.requestUpdate();
        return true;
      }
    }