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

BeamLocation has no listeners after beaming back #463

Closed
jmysliv opened this issue Jan 31, 2022 · 5 comments
Closed

BeamLocation has no listeners after beaming back #463

jmysliv opened this issue Jan 31, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@jmysliv
Copy link
Contributor

jmysliv commented Jan 31, 2022

Describe the bug

When beaming from location A to location B and then beaming back to location A, location A has no listeners. So when location A is a location with a custom state and we want to navigate fully declaratively we can't cause the _updateFromLocation listener callback is not registered.

I've managed to work around this by overriding the beamBack method and registering the listener manually, but I'm not sure if that's a proper solution.

class CustomBeamerDelegate extends BeamerDelegate {
  CustomBeamerDelegate({
    required LocationBuilder locationBuilder,
    String initialPath = '/',
    required List<BeamGuard> guards,
  }) : super(
          locationBuilder: locationBuilder,
          initialPath: initialPath,
          guards: guards,
        );

  @override
  bool beamBack({Object? data}) {
    // if we are beaming to the previous location, we register listener
    if (canBeamBack && beamingHistory.last.history.length <= 1) {
      final previousLocation =
          beamingHistory.elementAt(beamingHistory.length - 2);
      previousLocation.addListener(
        () => update(
          configuration: previousLocation.state.routeInformation,
          buildBeamLocation: false,
        ),
      );
    }
    return super.beamBack();
  }
}

Beamer version: 1.1.0

Expected behavior

After beaming back to the location, it should have the listener registered, so I can navigate in that location fully declarative.

@slovnicki
Copy link
Owner

Hi @jmysliv 👋
Thanks for creating an issue!

While refactoring in the past few weeks, I did notice that BeamLocations were not properly configured while using some beaming strategies. Glancing at the current source code, it looks like this should be fixed now, but I will create a specific test for it later today and get back to you with the confirmation.

@jmysliv
Copy link
Contributor Author

jmysliv commented Jan 31, 2022

@slovnicki thanks for the quick reply!

I'm waiting for confirmation then, let me know if I could help somehow.

@slovnicki
Copy link
Owner

Hey @jmysliv
I found the issue and pushed a fix. In the commit, there's also a test that indeed (naturally) failed before the fix.

Thanks for pointing this out! 💙

@slovnicki slovnicki added the bug Something isn't working label Jan 31, 2022
@jmysliv
Copy link
Contributor Author

jmysliv commented Feb 1, 2022

@slovnicki thanks!

When could I expect it to be released?

@slovnicki
Copy link
Owner

@jmysliv I expect to publish the next release this week, but you can try it out by depending on beamer directly from GitHub;

# in your pubspec.yaml
 beamer:
    git:
      url: https://github.com/slovnicki/beamer.git
      path: package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants