Giter Site home page Giter Site logo

Comments (12)

AlexandruIstrate avatar AlexandruIstrate commented on June 12, 2024 2

It seems like the PR by @bencochran fixes my problem. I'm happy to close the issue if that's alright with you.
Thanks for the help!

from workflow.

bencochran avatar bencochran commented on June 12, 2024 1

It looks like your ViewController is missing the addChild(container) and container.didMove(toParent:), resulting in UI events not being correctly delivered to the text field and the text field delegate methods in HelloViewController never being called. Put up a PR that appears to fix the issue on my end.

from workflow.

zach-klippenstein avatar zach-klippenstein commented on June 12, 2024

I'm not very familiar with Swift so this is just a guess, but this line looks suspicious to me:

.rendered(with: context, key: UUID().description)

Is that generating a new UUID every time? If so, all your child workflows will be restarted on every render pass, and the ones from the previous render pass will be stopped, which is why their sinks stop working.

from workflow.

AlexandruIstrate avatar AlexandruIstrate commented on June 12, 2024

You are indeed correct. UUID() generates a new universally unique identifier every time. That might be the problem. If I am correct, the key must be unique between all of the children. So I could use, for example, the name of the workflow, such as TextWorkflow or Child 1, Child 2, etc?
I'll give this a try and let you know if it works.
Thank you for the quick reply!

from workflow.

zach-klippenstein avatar zach-klippenstein commented on June 12, 2024

That should work. As long as the key is derived from something that identifies the child workflow consistently across render passes.

from workflow.

bencochran avatar bencochran commented on June 12, 2024

Yeah, you’ll need stable (and unique) keys between renders. I’d consider making some kind of identifier part of the items held in WorkflowData (like maybe var workflows: [(identifier: String, workflow: AnyWorkflow<…>], or a struct to wrap that up).

One other thing you’re going to need is to implement screenDidChange in your GraphViewController. When your workflow tree rerenders, the new root screen will be handed to that method to update itself and its children (calling update(screen:environment:) on each child DescribedViewController with its appropriate screen). Which also means you’ll need to keep those child view controllers around for use somewhere (another good use for the stable identifiers defined above).

from workflow.

AlexandruIstrate avatar AlexandruIstrate commented on June 12, 2024

Also, if I want to render children, should I use child.rendered(with:key:) or context.render(workflow:key:outputMap:)? What is the difference between the two?

from workflow.

AlexandruIstrate avatar AlexandruIstrate commented on June 12, 2024

I finally figured it out. It turns out the sink wasn't firing because of the way I was presenting my ContainerViewController. Instead of using present(_:animated:completion:), I was hosting the view controller as a child like this:

let container = ContainerViewController(
    workflow: GraphWorkflow(data: WorkflowData(key: "Root"))
)
        
let containerView = container.view!
self.view.addSubview(containerView)
containerView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
    containerView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
    containerView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
    containerView.topAnchor.constraint(equalTo: self.view.topAnchor),
    containerView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)
])

What I should have used was as simple as:

let container = ContainerViewController(
    workflow: GraphWorkflow(data: WorkflowData(key: "Root"))
)
present(container, animated: true, completion: nil)

Once I swapped out the initial code with the new version, everything started working. However, I would like to have the ContainerViewController embedded in another UIViewController, via an embed segue or just programatically. Is there any way to make that work and still have the sink operational?

from workflow.

dhavalshreyas avatar dhavalshreyas commented on June 12, 2024

Is there a sample project where this bug repros? Happy to look into it if there is.

Is the block that's calling sink.send() getting called? Is the Action.apply() getting called?

from workflow.

AlexandruIstrate avatar AlexandruIstrate commented on June 12, 2024

Is there a sample project where this bug repros? Happy to look into it if there is.

Is the block that's calling sink.send() getting called? Is the Action.apply() getting called?

Currently, I am using Square Workflow in a private project. I'm afraid I can't share the source code of that project. I do, however, have a test/demo project that consists of some simple code that essentially reproduces the bug in question. I can upload the demo project to GitHub if you would like to experiment with it. I would also make sure to mark the problem areas with comments and explanations.

from workflow.

dhavalshreyas avatar dhavalshreyas commented on June 12, 2024

Thanks @AlexandruIstrate! That'll be perfect.

from workflow.

AlexandruIstrate avatar AlexandruIstrate commented on June 12, 2024

I have created a repository with the demo project. Essentially, in the file ViewController.swift you have the choice between two methods (1 and 2). They are marked so that you know what each does. The difference between the two is that in one, the ViewController is getting presented modally over the top and in the other it gets embedded as a child.

Link to the repo: SquareWorkflowDemo

from workflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.