Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initializing routes not working #29

Open
mathieutozer opened this issue Jun 22, 2016 · 1 comment
Open

Initializing routes not working #29

mathieutozer opened this issue Jun 22, 2016 · 1 comment

Comments

@mathieutozer
Copy link

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!

@Ben-G
Copy link
Member

Ben-G commented Jun 24, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants