I've come across several instances of the need to refresh the data I'm displaying on Card A due to something that happens on Card B, usually the addition/deletion/change of data in the SQLite database I'musing.
What I hope might be possible is a scheme whereby Card B can send out some sort of global message that will be picked up by any cards that care about the data on Card B. I guess I could send events to every card that needs to know of the changes but I'd like to make it generic enough that I don;t have to worry about changing the cod to add another send if I introduce another stack into my application.
It doesn't seem like the normal message path will handle this since once the message gets picked up by a card, and assuming the card passes it along, the message travels further up the message path which would exclude any other cards that need to know about it.
The other option would be for me to refresh all the data on a card every time it comes into focus but that doesn't seem very efficient.
Am I missing something obvious or can someone point me in the right direction please?
Thanks,
Pete
Notification of need to refresh data
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Notification of need to refresh data
Pete,
if I understand you correctly then you could set the custom property, lets say of the stack when you have changes on card Blikewise you could set a global variable to true.
On preopencard you could do your update of card A.
If you have many different cards that are visited with different frequency then you could put a timestamp into your "the uCardBWasChanged of this stack"
Card A,C,D would check a custom property of their own which stores the last update they didThis avoids unnecessary updates.
Otherwise you would have to go for a broadcasting system in which all cards/controls in need of update would be registered and the update is triggered with one command
regards
Bernd
if I understand you correctly then you could set the custom property, lets say of the stack when you have changes on card B
Code: Select all
set the uCardBWasChanged of this stack to true
On preopencard you could do your update of card A.
If you have many different cards that are visited with different frequency then you could put a timestamp into your "the uCardBWasChanged of this stack"
Card A,C,D would check a custom property of their own which stores the last update they did
Code: Select all
on preopencard
if the uIDidUpdate of this card <> the uCardBWasChanged of this stack then
do you update
set the uIDidUpdate of this card to the uCardBWasChanged of this stack
end preopencard
Otherwise you would have to go for a broadcasting system in which all cards/controls in need of update would be registered and the update is triggered with one command
regards
Bernd
Re: Notification of need to refresh data
Thanks Bernd. As well as when a card is opened, I need to do this when an already opened card (Card A) receives focus after the user has been working on another card (Card B). Your solution will still work though, looks like the resumeStack event would be the place to put the code.
Your mention of a broadcast system is interesting to me as well. Have you implemented such a thing? It sounds like you're suggesting some sort of central repository where objects could register their interest in certain events, coupled with a command that would go through that registry looking for a specific event type and send a message to every object?
Thanks,
Pete
Your mention of a broadcast system is interesting to me as well. Have you implemented such a thing? It sounds like you're suggesting some sort of central repository where objects could register their interest in certain events, coupled with a command that would go through that registry looking for a specific event type and send a message to every object?
Thanks,
Pete
-
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Notification of need to refresh data
No, I have not implemented such a system. I just read that the GLX framework has such a mechanism. http://www.bluemangolearning.com/revolu ... framework/ But one could think of a way to implement that. The central repository of receivers could be a custom property of the stack. You put the e.g. the long id of all receivers into a list in that property.phaworth wrote:Your mention of a broadcast system is interesting to me as well. Have you implemented such a thing?
Than there would be a handler that is triggered by the sending object, your card B for example.
The handler would use the custom property and sends an update command to all receivers, which of course need a script to handle the update command and initialise the update.
Sounds a little complicated but should be feasible.
regards
Bernd
-
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Notification of need to refresh data
Pete, you could trap the resumeStack and issue a preopencard messagephaworth wrote: looks like the resumeStack event would be the place to put the code.
Code: Select all
on resumeStack
send preopencard to the current card
pass resumeStack -- just in case
end resumeStack
regards
Bernd