Git Product home page Git Product logo

Comments (9)

LostInBrittany avatar LostInBrittany commented on July 27, 2024 2

I've just done an UniFlow version of the Polymer Starter Kit, where I try to do the routing operations using actions.
All feedback is welcome...

from uniflow-polymer.

militeev avatar militeev commented on July 27, 2024 1

I have not used app-route in production app, so might not know all the details about it. However I don't see a reason to put inside . I would simply make route part of the state (state.route) which would give the ability to manipulate it from the dispatcher.

from uniflow-polymer.

mbinette avatar mbinette commented on July 27, 2024

A few quick tests of using observers show that you can use them to either monitor the entire tree onStateChanged(state.*) or a portion of the tree, onStateChanged(state.auth.*), or a specific value in the tree, onStateChanged(state.auth.user)` just like Polymer documentation says you can.

So that does handle the checking for a logged in user. Now to figure out routing.

from uniflow-polymer.

mbinette avatar mbinette commented on July 27, 2024

This does work. I had to do two things to make it work, maybe because of the order things get created, not sure?

First I updated <app-location id="location" route="{{state.route}}">. That alone does not do it. state.route does not get updated. I also had to set state.route to the app-location route object like so:

ready: function() {
  this.set('state', {
    route: this.$.location.route
  });
},

I tried setting state.route to {} in ready but that doesn't work.

I'm not positive I'll stick with this though. is meant to be chained using pattern, data, and tail properties. I'm going to experiment more with this compared to passing the tail value into specific dispatchers.

from uniflow-polymer.

militeev avatar militeev commented on July 27, 2024

That makes sense. <app-location> uses two-way binding for route, which makes it a bit difficult to use in uniflow pattern (in which elements either listen to state changes or mutate state, but never both). Do you have your app on GitHub somewhere for me to take a look and see if I can suggest something for your specific case?

from uniflow-polymer.

mbinette avatar mbinette commented on July 27, 2024

Also using chained routers (passing tail to route of component) we are able to only manage the portion of the URL we are displaying and don't need to worry about where it was called from in the URL chain making it easier to use the same component that has routing from multiple locations in the app.

The app is closed source so I don't have something to show you. I'm going to test not using state in app-router and also not passing the routing information to the dispatchers. That won't work either since the routers need to be chained.

Instead, I'm going to use the emitAction to save data and then use the standard fire method from the action to let my components know to change route if needed. In the original SAVE_USER example that would mean the component's save method would simply validate the form and emit a SAVE_USER message with the model. It (or the parent of it) would listen for a standard 'user-saved' message and handle routing.

from uniflow-polymer.

mbinette avatar mbinette commented on July 27, 2024

Looks good. Where I'd want to see more is a link in view1 to view2, a button in view2 to view3, and also a use of the BACK action. I use a type of BACK action in my app when someone hits cancel on some of my pages. Nice that you don't need to worry where exactly they came from when they hit Cancel, especially when that page is called from multiple locations.

The other issue I ran into was nested app-route components. So if view1 had an iron-pages on it and used a route that was passed in from the app's app-route tail property to determine which page to show. How can that be handled with UniFlow cleanly. I'm sure it can, just need something like that level of sophistication in the starter app so people don't hit a roadblock on day 2. So how would /view1/page1 and /view1/page2 get handled.

My current non UniFlow solution differs by returning a promise for its emitAction equivalent. That allows me to do some routing right from the component. Emit save, wait for success, then fire a standard event like this.fire('save-clicked') for higher components. I tried to fire events from my action dispatcher but since it is at the root of the application, the event didn't go anywhere. Events bubble up, not down. I had to pass in the calling element which seemed dirty. With a promise in UniFlow you could call the emitAction CHANGE_PAGE event from the component rather than from the action dispatcher. Of course the initial emitAction to SAVE could include an onSuccessPage value that could be passed to CHANGE_PAGE on success. So many ways to do it :-)

from uniflow-polymer.

militeev avatar militeev commented on July 27, 2024

@LostInBrittany Thanks a lot for your work! I made some comments here: code review, but overall looks great as a starting point. I would be happy to contribute by adding more non-trivial scenarios on how UniFlow can be used, but the problem is as usual: finding time to do that. So can't promise anything at this time, but will keep this in mind in case I'll have some spare cycles.

from uniflow-polymer.

RobMaskell avatar RobMaskell commented on July 27, 2024

I have also had a go at Polymer 2.0 + Uniflow + app-location, app-route integration. I wanted changing the URL in the address bar, links to work also and to have some state change with the page (in the real app it would be a rest call to pull back data for the page).

It sort of works but I've come across an issue, it seems that when the app loads (first time, and when the URL is changed) the emit of the page event is firing before the action-dispatcher is ready to receive the event although the code works fine when triggered in other situations without a full app reload. Is there a way to prevent emits of actions until the dispatcher is ready?

Could be my understanding of either polymer or uniflow though, but I'd appreciate some help as I can't see how to fix it.

I did look at what @LostInBrittany had done but I couldn't see how it would do what I wanted.

Repo here - https://github.com/RobMaskell/PolymerSandbox

from uniflow-polymer.

Related Issues (14)

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.