Hi Refresh,
I had a very productive hacking weekend, and I am wondering if anyone has
stumbled upon the technique that I stumbled upon.
As we all know, web applications are moving more and more towards
client/server applications where JavaScript handles as much of the
user-facing stuff as possible, while the server stores things and does any
heavy lifting stuff in the background.
I find it frustrating, however, to constantly update my JavaScript clients
to match new functionality on the server. That is, if I add $object->foo()
on my server, I have to create a matching function in Javascript and a
matching API handler.
That is, until now. This weekend, I built a client/server pare that, in
addition to returning the data necessary for the client, also returns a list
of methods available to be taken on that data.
So, we have something like:
CLIENT: calls /api/object?id=1
SERVER: Loads object 1. Then, examines the object and gets a list of all of
its object methods. Returns a json object where json.data = object 1, and
json.methods = a list of methods that can be called on object 1.
CLIENT: creates javascript representation of object 1, then dynamically
appends each method in json.methods to the object.
The result is, if I add a method on the server, it is immediately available
natively in JavaScript, without modifying the server API code, and without
modifying the Javascript.
To be clear, I am not using a wildcard function handler in Javascript to
achieve this. I am actually creating native functions and appending them to
the javascript object as it is being created. So, instead of
obj.callAPIMethod('foo'), I get obj.foo();
Has anyone on the list ever done something like this? Does this technique
have a proper name? It seems like a very powerful technique which could be
applied to a many different situations... especially when the server changes
a lot or may not have the same functionality in every instance.
Thoughts?
--
Our Web site: http://www.RefreshAustin.org/
You received this message because you are subscribed to the Google Groups
"Refresh Austin" group.
[ Posting ]
To post to this group, send email to [email protected]
Job-related postings should follow http://tr.im/refreshaustinjobspolicy
We do not accept job posts from recruiters.
[ Unsubscribe ]
To unsubscribe from this group, send email to
[email protected]
[ More Info ]
For more options, visit this group at
http://groups.google.com/group/Refresh-Austin