What you are trying to accomplish is the same thing that I came across with the Agile Toolkit.
http://agiletoolkit.org/intro/javascript - scroll down to an example that loads a form / grid through an AJAX request. It does exactly what you are trying to do - it loads the widget along with JavaScript and does just what it needs.
The difficulties I encountered were: - loading and executing javascript. I had to write my own handler that I use. It is built on top of $ .ajax. This layer handles things like session expiration, multiple user clicks, slow loads. - Framework should take control of JavaScript. For this I use jQuery Chains. It basically creates an object that can be attached to any widget (or view in our lingui) and will only be displayed on output if the widget also renders. When you perform a partial reboot, you should only show the appropriate JS.
So your Script method is exactly the same as the js () function: https://github.com/atk4/atk4/blob/master/lib/AbstractView.php#L250
My opinion, of course, is that abstracting views in this way and separating JavaScript is a great way. I have seen so many AJAX crashes on rich websites like Amazon EC console, Github etc. Etc., And not one of them happens in the software that we create in the Agile Toolkit. Even in development, all javascript behaves very intelligently and predictably.
We have come to the point of fully creating complete accounting software in AJAX. People use it for hours without updating one page. Many jQuery plugins had to be converted to a WidgetFactory to properly destroy themselves. And the development of such software is simply amazing.
romaninsh
source share