[ANN] SSNotification
Posted: 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
To listen for a notification
To send out a notification
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
Button B
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
https://shaosean.tk/SSNotificationLiveCode.html
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"
Code: Select all
Listen "notificationName"
Code: Select all
Notify "notificationName"
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 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
https://shaosean.tk/SSNotificationLiveCode.html