Skip to content

Conversation

@adamghill
Copy link
Owner

No description provided.

@adamghill adamghill self-assigned this Dec 17, 2020
@adamghill
Copy link
Owner Author

Inspired by #97.

@frbor
Copy link

frbor commented Dec 17, 2020

Hi,

I got this to work, but I had to change some code to check for redirect.url as well:

component-redirect...frbor:component-redirect

Without this change I was redirected to /.../undefined in some components, even when no redirect values were returned.

I'm not that familiar with javascript, but it looks like {} is a truthy value?

However, I liked the generic change here where you can return other types in the future. I was looking into whether it is possible to "stop polling", and maybe the return logic can be reused there as well?

Nice work!

@adamghill
Copy link
Owner Author

Oh 🤦, yeah I need a better check for that redirect value. Thanks for pointing that out to me -- this is what I get for not testing thoroughly before making a PR! :)

My plan was to expose a returnValue or lastReturnValue or something that could be retrieved in Javascript, but I'm not quite sure how to expose it. Initially, I was thinking of something like Unicorn.lastReturnValue('hello-world') (similar to https://www.django-unicorn.com/documentation/components/actions#calling-methods), but I'm not sure how helpful that might be. Another option is create a special variable like $returnValue (similar to https://www.django-unicorn.com/documentation/components/actions#special-arguments). If you have thoughts about either, that would be useful.

Stopping polling is a good idea I hadn't thought of. Maybe something like u:poll.stop=stopper (where stopper could be a field, property, or method in the component) would be useful?

@frbor
Copy link

frbor commented Dec 18, 2020

Unfortunately I do not have any good ideas regarding your question on the exposed returnValue/lastReturnValue.

To stop polling using u:poll.stop=stopper sounds like it will work out nicely.

The other option might be to use return values with a special Object on the component, that then needs to be checked like you do with redirect. So for instance:

Ship this simple class with django-unicorn:

class UpdatePolling:
    def __init__(self, disable=False, refresh_time=None):
        self.disable = disable
        self.refresh_time = refresh_time

which then ca be used for both disabling polling and updating refresh_time:

def save_book1(self):
    book = Book(title="Title)
    book.save()

    return UpdatePolling(disable=True)

def save_book2(self):
    book = Book(title="Title)
    book.save()

    return UpdatePolling(refresh_time=4000)

During testing I did find use of disabling polling, but others might find use for update the refresh_timer. However, the idea with u:poll.stop=stopper is somewhat easier so I might think that is just as good idea.

Sorry for cluttering this PR with the ideas on updating polling.

br, Fredrik

@adamghill
Copy link
Owner Author

Sorry for cluttering this PR with the ideas on updating polling.

No worries! I ended up moving the "stop polling" request to #99, but I appreciate all of your thoughts. I'll try to figure out a simple API for this use-case, too.

@adamghill adamghill merged commit 213d7ba into master Dec 19, 2020
@adamghill adamghill deleted the component-redirect branch December 19, 2020 02:44
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

Successfully merging this pull request may close these issues.

2 participants