Before and after Livecode

David Bovill david at viral.academy
Sun Jul 19 16:37:38 CEST 2015


Oh wow - it get's better.

Say you have a handler - that processes some information from a request and
then sends out a response. In my case the server bundles useful stuff into
a requestArray, and after it has been routed a handler processes it and
sends back a reply to the browser. The handler looks like this:

*command* process_UnGot socketID, requestArray
>    *put* requestArray ["someInput"] && "is flexible!" into someMessage
>    daemon_SendJSON socketID, someMessage
>    *return* "An ungot url path"
> *end* process_UnGot


So let's say we want to modify this processing in some way - but not touch
the code. We can override the handler, by using the same "process_UnGot" -
but what if we want to just modify the data and let the existing code do
it's thing. how can we put stuff into the requestArray without altering the
existing code?

Well damned me if you can't use the following before handler in another
script:

before process_UnGot socketID, @requestArray
>    *put* "rubbish" into requestArray ["test"]
> *end* process_UnGot


Note the "@" - it's not in the original handler - but it still works!
Inject anything you want into any existing handler without messing with
your existing code. Middleware just got sexy.


On 19 July 2015 at 02:19, Mark Wieder <mwieder at ahsoftware.net> wrote:

> On 07/18/2015 12:28 PM, David Bovill wrote:
>
>  Now with before / after handlers - no logging code in the server - it's so
>> clean and simple it is gorgeous. When I want logging I add the behavior
>> which includes all the efore / after handlers that havve acess to all the
>> data and just do the logging. When I don;t want them I remove the
>> behavior.
>> Nice.
>>
>
> Brilliant.
>
> --
>  Mark Wieder
>  ahsoftware at gmail.com
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


More information about the use-livecode mailing list