Issue re: system.perspective.sendMessage()

I am attempting to pass parameters between multiple views, and it's my understanding that this is the preferred way to do so according to the documentation:

In Perspective, Component Message Handlers are the preferred way to pass parameters between components or Views. Doing this involves the system.perspective.sendMessage function.

I have a view where users can query a database which populates the results in a table's rows. Users need to be able to select a row and click a button to redirect to a different view where that row's values will be used to populate a group of text fields and run a named query those values as its parameters to populate a table below those fields.

Right now, I am sending the first table's selection as the payload of a session-scoped message. The other view has message handlers on components that receive that payload and run scripts to update themselves. The line after sending the message runs system.perspective.navigate(). This works fine in the designer. If I click the button that would redirect to that view, I can verify that the other view is receiving the message through console logging, and when I open that view everything is loaded as I'd expect. However, in a live session, the second view is not updating at all. I originally assumed this was because sendMessage() is async, and the navigate() call was opening the page before the message handlers had time to execute. However, I put in a sleep() call before the redirect, and still saw no updates. I then broke the sendMessage() and navigate() calls into separate buttons, but I'm still not able to get the second view to update, or even give any indication that it's receiving the message being sent. What can I do to resolve this? And is this even the proper way to go about this process? Based on my experience with the documentation, I would assume this strategy would be correct, but I find conceptualizing with the async execution to be difficult without promises like there are in traditional web development. Any help or guidance would be appreciated, as I'm quite stumped on how to fulfill my company's requirements re: this functionality using Perspective.

If you're navigating to a view, just pass the parameters... as parameters.
That's not what messages are for.
You'd use messages to send data to another view while both are opened.
The typical example is popups. Some button opens a popup, and actions in the popup modify the calling view. Send a message.

But for passing parameters when navigating ? Hell no !

2 Likes

Thanks for clarifying that! Using the params object in the navigate() call is what I've been implementing in the meantime, though I figured it wasn't ideal (see the documentation excerpt above). I'm still not sure how to trigger that table update before the view is rendered. Any "ignition proper" way to achieve that? My first thought would be to run the namedQuery on the original view, pass the dataset as a param, and bind the table's prop.data to that incoming dataset. Does that sound right?

Are you trying to avoid loading times due to a slow query ?

The proper way is to simply bind the table to the query, and let it do its job.
A transform can help post-process the data returned by the query if you need to modify it.

If it takes too long, first make sure that the query is "sane".
If it's inherently long, you can try finding alternative ways: pre-fetch the data, use a cache...
Or accept that it takes a little while. Maybe display a spinner or some warning that the data is loading.

1 Like