Sunday, February 9, 2014

Does _your_ data model create your javascript?

So still early days, but currently I'm working on creating javascript from D data models.
Why would anyone want to do this exactly? And how did I come to this?

So little background. I have recently added a restful api generator for data models. It requires being hooked into the router for Cmsed. As I already had a viable model registration, router registration system. It isn't too hard to hook this into creating javascript for a data model itself.

The hardest part about all this is pushing any required javascript libraries into the static router (written just for this).
Now the trigger for wanting this was an issue created on Vibe's issue tracker link.

Dvorm has a query system and the restful api generator includes support for this.
For the actual javascript generator I will be assuming it is opt out and you can pick the ajax library and OOP library. You should also be able to ignore certain properties should the need arise i.e. internal only.

So what does this exactly look like? For just the javascript side of things:

get:/public/js/prototype1_7_1
get:/public/js/oophandler
get:/public/js/jsface2_2_0
get:/public/js/jsface
get:/public/js/models/page3
get:/public/js/ajaxhandler
get:/public/js/prototype
get:/public/js/models/books3

The above is all the routes generated, given JSFace v2.2.0 and Prototype v1.7.1.
Now there was an issue that I had no planned for. The router did not like a function generated class. So because of this, now every restful route has to be done by the developer. There is no customization per model. That wouldn't be too hard to add but I want to make it clear from the get go that it should be standardised into one location. As a web service its important to keep e.g. routes similar.
This prevents another interesting dimension. Filtering of restful routes. Think about it. After all data models could be required to be admin only or authed only.



Now with the aid of globally setting the route prefix to use in the javascript model generation, you can quite easily use it.



The base data model was:



This technology really adds a neat possibility and time improvements to web development! Although my target is never small sites, more medium to large web development projects. Only there this type of work really pays off.

I have yet to implement the query system provided by dvorm. However I will most likely push that out for later. As I want to work on other things.

No comments:

Post a Comment