[ANN] SSNotification

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
Posts: 907
Joined: Thu Nov 04, 2010 7:53 am

[ANN] SSNotification

Post by shaosean » Fri Nov 10, 2017 4:38 pm

What it is
This is a script-only stack that allows your application to listen for and broadcast internal notifications. Similar to NSNotificationCenter

Why would I use this
While you can probably do something very similar with 'send' and 'dispatch' (heck, the code is written using dispatch) you would need to know the target objects and adding new objects to your project would require you to make sure that you remember to update your code.. If your project has loadable stacks, this makes it even easier for you to have those stacks interface with your main application without even knowing anything about it..

Sounds weird, but how does it work
First thing you would need to do is to load the script and then bring it in to use with the "start using" command..
Now, any objects that you want to register you just call the 'Listen' command, along with a notification name (explained better below)
And finally, your code can send out notifications with the 'Notify' command..

Quick and dirty docs
To bring the stack in to use

Code: Select all

start using stack "SSNotification"
To listen for a notification

Code: Select all

Listen "notificationName"
To send out a notification

Code: Select all

Notify "notificationName"
notificationName is whatever you want, but it has to follow the naming conventions for command names.. The notificationName will be the name of a command that will get called when the object receives the notification..

Quick and dirty sample
the script stack has been loaded in to memory and brought in to use already

Button A

Code: Select all

on mouseUp
  Listen "anotherMouseUp"
end mouseUp
on anotherMouseUp buttonName
  put buttonName
end anotherMouseUp

Button B

Code: Select all

on mouseUp
  Notify "anotherMouseUp", the short name of me
end mouseUp
Clicking on button A will cause it to listen for the notification "anotherMouseUp" and when it receives that notification, the command "anotherMouseUp" is called..

Clicking on button B will cause it to send out the notification "anotherMouseUp" with a single parameter (the button's short name)..

ps.. yes, i suck at documentation, anyone want to do a better job? ;)

Okay, this sounds like it was written by a baboon, but I'll try it anyways
(1.28 KiB) Downloaded 18 times

Posts: 168
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: [ANN] SSNotification

Post by jiml » Sat Nov 11, 2017 4:46 pm

Thank you for SSNotification. Very handy!
Jim Lambert

VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4699
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN

Re: [ANN] SSNotification

Post by jacque » Sat Nov 11, 2017 5:01 pm

Thanks for this, it's a useful addition. It's going into my keeper folder.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Posts: 907
Joined: Thu Nov 04, 2010 7:53 am

Re: [ANN] SSNotification

Post by shaosean » Sun Nov 12, 2017 4:33 am

You're welcome.. One thing I forgot to mention, if the object that is Listening is no longer in memory the library code will remove the reference to that listener (yay, auto-clean ups :D )

oh.. and the code is in the Public Domain <http://unlicense.org/>, as it was written in TextEdit and not in LiveCode..

Post Reply

Return to “Talking LiveCode”