ReSwift-Router icon indicating copy to clipboard operation
ReSwift-Router copied to clipboard

Initializing routes not working

Open mathieutozer opened this issue 8 years ago • 1 comments

I have an issue where the extension with the fatal error is being called instead of my custom procol conforming classes. I probably haven't set everything up right... here's the relevant code - also not that this is a macOS app but that shouldn't matter...

let store = Store<AppState> (
  reducer: AppReducer(),
  state: nil
)

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {


  //let appState: AppState
  let router: Router<AppState>
  override init() {
    //self.appState = AppState(realmState: nil, navigationState: NavigationState())
    router = Router(store: store, rootRoutable: MainWindowRouter()) { state in
      state.navigationState
    }
    store.dispatch(
      SetRouteAction([Window.EditorWindow.rawValue])
    )
    super.init()
  }

  func applicationDidFinishLaunching(aNotification: NSNotification) {
    // Insert code here to initialize your application

  }

  func applicationWillTerminate(aNotification: NSNotification) {
    // Insert code here to tear down your application
  }

  @IBAction func openPreferences(sender: AnyObject) {
    store.dispatch(
      SetRouteAction([Window.Preferences.rawValue])
    )
  }
}
struct AppState: StateType {

  let realmState: RealmState?
  let navigationState: NavigationState

  init (realmState: RealmState?, navigationState: NavigationState) {
    self.realmState = realmState
    self.navigationState = navigationState
  }
}

class MainWindowRouter: Routable {

// I've set breakpoints, and none of these get called
  func changeRouteSegment(from: RouteElementIdentifier,
                          to: RouteElementIdentifier,
                          completionHandler: RoutingCompletionHandler) -> Routable {

    completionHandler()
    return self

  }

  func pushRouteSegment(routeElementIdentifier: RouteElementIdentifier,
                        completionHandler: RoutingCompletionHandler) -> Routable {
    if routeElementIdentifier == "EditorWindow" {
      let mainWindow = NSStoryboard(name: "Main", bundle: nil).instantiateInitialController() as! Routable
      completionHandler()
      return mainWindow
    }
    return self
  }

  func popRouteSegment(routeElementIdentifier: RouteElementIdentifier,
                       completionHandler: RoutingCompletionHandler) {
    completionHandler()
    if routeElementIdentifier == "EditorWindow" {

    }
  }
}

Am I missing something? The tests don't appear to be doing anything else, and I've scoured the documentation!

mathieutozer avatar Jun 22 '16 00:06 mathieutozer

Hey @mathieutozer, sorry that you're facing this issue! Are you using 0.2.6 or 0.2.7 of ReSwift-Router? If so, the method signatures have changed. The routing methods now carry an animated flag that indicates whether the Routable should route animated or un-animated. Here's an example:

    public func pushRouteSegment(
        routeElementIdentifier: RouteElementIdentifier,
        animated: Bool,
        completionHandler: RoutingCompletionHandler) -> Routable {
             ...
    }

By matching this signature you should be able to solve your issue. I really need to fix this as suggested in #25 and remove the default route implementations and come up with a better solution for this.

Sorry for the inconvenience & I hope this helps.

Ben-G avatar Jun 24 '16 05:06 Ben-G