Publish/subscribe?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Fjord
Posts: 132
Joined: Sat Dec 06, 2008 6:18 pm
Location: France

Publish/subscribe?

Post by Fjord » Wed Mar 02, 2022 2:28 pm

I'm building a system using 4 stacks and it's getting kinda messy.
Now, I bought and was reading the nice book "Livecode Advanced Application Architecture" by Ande Garzia. He mentions the publish/subscribe mechanism, and I thought it would be nice to try it. He also mentions a publish/subscribe package that's supposed to be linked [how?] with the book but it doesn't come with the book and I couldn't find it anywhere on the web.

Today I thought of looking here and found this.
Re: Resize-aware fields?
by stam » Thu Feb 03, 2022 6:46 pm
(…)
is there some kind of publish/subscribe mechanism i can take advantage of
Maybe someone here can point me to either the code mentioned by Ande Garzia or some other code along the same line…?
--
François

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Publish/subscribe?

Post by richmond62 » Wed Mar 02, 2022 2:36 pm

Why don't you contact Andre Garzia directly and ask him?

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Publish/subscribe?

Post by stam » Wed Mar 02, 2022 4:12 pm

Fjord wrote:
Wed Mar 02, 2022 2:28 pm
I'm building a system using 4 stacks and it's getting kinda messy.
Now, I bought and was reading the nice book "Livecode Advanced Application Architecture" by Ande Garzia. He mentions the publish/subscribe mechanism, and I thought it would be nice to try it. He also mentions a publish/subscribe package that's supposed to be linked [how?] with the book but it doesn't come with the book and I couldn't find it anywhere on the web.

Today I thought of looking here and found this.
Re: Resize-aware fields?
by stam » Thu Feb 03, 2022 6:46 pm
(…)
is there some kind of publish/subscribe mechanism i can take advantage of
Maybe someone here can point me to either the code mentioned by Ande Garzia or some other code along the same line…?

Hi Fjord - Probably best to contact Andre directly.
His handle on this forum is SoapDog - just send him an IM.
If you have no luck, IM me and i can try and dig out the files for you as i too bought that book some time ago.
Not sure what the licence for these files is so not sharing on this forum.


On a related note however - i've considered this pattern several times but haven't really put it into use. LC offers many mechanisms to overcome the same issues, and it always seems much simpler and easier to just use the built in mechanisms (which is how i very effectively solved the issue you quote me on above)

Andre's book is very good in many respects; the publish/subscribe code seems more like trying to bend LC into an MVC pattern, in a way LC isn't really designed for. However i do follow some of the advice given and more recently i'm taken to using scriptOnlyStacks for model/view/controllers as my app was becoming unwieldy. But putting the necessary handlers needed by other script files in the backscripts, they're now available to all stacks and it works just fine.

Andre's publish/subscribe stack is essentially an array where each object wanting to subscribe to a message has to register individually and then you have to broadcast messages individually as well (these are user-defined messages, not system messages like mouseUp) - in all in amounts to extra code that isn't always needed.

It works, but is not simple and I suspect will end up needing just as much coding as other methods.
I haven't really put this into practice and if you do your mileage will definitely vary - let us know how this works out for you!
Stam

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Publish/subscribe?

Post by FourthWorld » Wed Mar 02, 2022 9:13 pm

Pub/sub can be a good pattern in some cases, but to better understand you goal can you describe how behaviors are insufficient in your app's model?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Fjord
Posts: 132
Joined: Sat Dec 06, 2008 6:18 pm
Location: France

Re: Publish/subscribe?

Post by Fjord » Thu Mar 03, 2022 12:21 pm

@Richard

I never said it's insufficient. Actually, I don't really like behaviours because I find them kinda messy and never saw (or thought of) a systematic way to use them.

I just read, not for the 1st time, about MVC architecture,
  was thinking it might be interesting to clarify my project,
    found it calls for a way to organise communications between different parts (which I never realised before)
      and want to look at how people are programming it
        before I come up with my own solution if needed.
--
François

Fjord
Posts: 132
Joined: Sat Dec 06, 2008 6:18 pm
Location: France

Re: Publish/subscribe?

Post by Fjord » Mon Mar 14, 2022 4:01 am

@Richard
can you describe how behaviors are insufficient in your app's model?
Actually, what I’m looking for is a systematic design strategy, applicable in LC.
What is you strategy to build an app around behaviours?
Could you be so kind to point me to some docs?
--
François

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Publish/subscribe?

Post by stam » Mon Mar 14, 2022 4:39 am

For what it's worth, with my latest app I've gone almost exclusively to scriptOnlyStacks precisely to implement an MVC approach. More of an experiment in progress really...

I've created 6 Model scriptOnlyStacks that strictly deal with getting/setting/housekeeping data in the models
i've created View scriptOnlyStacks that manage the interface for each card (basically replacing the card scripts but moving was much as possible out of controls and into card scripts)
Ive created Controller scripts and some 'general library' scriptOnlyStacks. Some of this are quite short - for example i have a scriptOnlyStack that specifically serves up location of the other scriptOnlyStacks depending on whether running in IDE or standalone.

The problem with this setup is that a lot of the models need to use handlers that are not directly in the message path - rather than individually 'start using' these stacks I've loaded all these 'common utility' scripts into the backscripts so they're always available and this seems to work well.

The benefit of this is i can use VSCode for the editing and it works better with GitHub. But more importantly, by compartmentalising into many scriptOnlyStacks, larger projects become more manageable...

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Publish/subscribe?

Post by FourthWorld » Mon Mar 14, 2022 8:49 am

Fjord wrote:
Mon Mar 14, 2022 4:01 am
@Richard
can you describe how behaviors are insufficient in your app's model?
Actually, what I’m looking for is a systematic design strategy, applicable in LC.
What is you strategy to build an app around behaviours?
It's an interesting question. I hadn't really though about it. I build from functionality outward, so architecture fits function; it hadn't occurred to me to establish an architecture first and then figure out how to make the functionality fit into it.

I build interfaces. I put the code at the level most appropriate for its scope. Things likely to be used in other apps wind up in libraries.

Sometimes I group controls and reuse the group. I use behaviors for those. And a few other things, wherever a single script can benefit multiple objects.

What are you building?
Could you be so kind to point me to some docs?
What would you like to read about first?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Publish/subscribe?

Post by stam » Wed Mar 06, 2024 9:59 am

As a belated answer to the OP as well as for anyone searching for Publish-Subscribe functionality in LC (not always needed, but good to have if it is): https://github.com/stam66/skPubSub

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”