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

Navigation with Flow destroys Mortar-Scopes on FORWARD transition due to path.elements() not being maintained by anything #116

Closed
Zhuinden opened this issue Dec 29, 2015 · 1 comment

Comments

@Zhuinden
Copy link

The PathContext instances are built as [ROOT; CURRENT_PATH] and [ROOT; NEXT_PATH] as the paths actually have no knowledge of the previous paths, even though the elements() method is called. The elements() only contains the ROOT and the path itself.

I've fixed this by mirroring some classes from Flow

public final void executeTraversal(PathContainerView view, Flow.Traversal traversal, final Flow.TraversalCallback callback) {
    final View oldChild = view.getCurrentChild();
    Path path = traversal.destination.top();
    int i;
    if(traversal.direction == Flow.Direction.FORWARD) {
        Iterator<Object> _destinationPaths = traversal.destination.reverseIterator();
        i = 1; // 0 is ROOT in PathContext! DO NOT CHANGE TO 0
        while(_destinationPaths.hasNext()) {
            Path destinationPath = (Path) _destinationPaths.next();
            if(destinationPath != path) {
                path.elements().add(i, destinationPath);
            }
            i++;
        }
    }
    //...

and

/**
 * Finds the tail of this path which is not in the given path, and destroys it.
 */
public void destroyNotIn(PathContext path, PathContextFactory factory) {
    Iterator<Path> aElements = this.path.elements().iterator();
    Iterator<Path> bElements = path.path.elements().iterator();
    while(aElements.hasNext() && bElements.hasNext()) {
        Path aElement = aElements.next();
        Path bElement = bElements.next();
        if(!aElement.equals(bElement)) {
            factory.tearDownContext(contexts.get(aElement));
            break;
        }
    }
    while(aElements.hasNext()) {
        Path aElement = aElements.next();
        factory.tearDownContext(contexts.get(aElement));
    }
}

I should probably make a pull request about this, but I'm using 0.12 and I'm not sure if anything has changed since then.

@loganj
Copy link
Collaborator

loganj commented Feb 4, 2016

This shouldn't happen with changes on master. I'll be sure to test/demo.

@loganj loganj closed this as completed Feb 4, 2016
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