[OT] JS Design Patterns [was] PURE in Reverse?

3 views
Skip to first unread message

AJ ONeal

unread,
Jan 12, 2010, 1:59:32 PM1/12/10
to pure-unobtrusive...@googlegroups.com
I've considered this idea:
<input name="person.name" ...>

But it needs to be like this:
<input name="person[name]" ...>
or this
<input name="people[][name]" ...>

because that's what PHP, Ruby, Python, etc expect it to be.



I don't have a firm understanding of many Design Patterns yet, but I'm forming some ideas on a variation of a Dual-MVC which I call DoubleDIP (Data-Interface-Presenter) from what I've learned with the various ORMs I've dabbled with.


Transport Model - (JSON) - a hash, the properties of which probably map 1:1 with the Class, which transmit in plain text when traversing systems

Class - (Javascript Classes ) - manipulates the model
Mapper - (jQuery.jStore) - maps the Model hash (or Class) to the DataStore
DataStore - (DOM, LocalStorage, Cookies, Flash) - SQL, NoSQL, whatever. (HTML5 localstorage uses a NoSQL key/value store with a SQL backend... which is interesting because many SQL engines use key/value store backends such as BerkleyDB)

Controller - (jQuery) - The application code itself

Presenter - (PURE) - That which the Controller uses to map the Model to the View (and Ideally, can go in reverse as well)
Template - (PURE directive) - The Presenter is to the Template what the Mapper is to the DataStore.
View - (HTML) - What the user interacts with


* Javascript is tricky because it has three DataStores. In HTML5 in has LocalStorage and, as always, it has the Web Service and the DOM. However, the mapper can be configured to read from any or multiple of the three of these on a per-class basis. For some classes localStorage is a cache, for other classes localStorage may be the sole storage of the data (perhaps the Web Service only does processing, or some data must legally remain private).


This pattern focuses on the idea of mutual exclusion between a Web Service is its own deal and a Client application is its own deal and the two never cross barriers except where the Presenter of the one becomes the Data of the other. (Whereas every Web Service I've presently seen - Flickr, for example - has two APIs: one for internal use, the other for external use.

The goal of my 'DoubleDIP' pattern is that I can go 'File -> Save As' on the webpage, and then open it from the desktop and it still has all of the same data, is still logged in, and functions the same as it did before.

Additionally, I think that this design pattern can circumvent some licensing restrictions and patents, as the data always remains a distinct entity regardless of how it is processed on either end.

Anyway, those are some semi-off the cuff thoughts, perhaps premature.

AJ ONeal


On Tue, Jan 12, 2010 at 1:49 AM, chloec <chl...@gmail.com> wrote:
A simple directive like 'input@value':'person.name' would be easy to
reverse.
But if you start using a function or concatenation, that's becoming
harder to reverse.

I tried different approaches, but I haven't find a simple and fast one
so far.
Do you have an idea on how it would ideally work?
Would some techniques you know from SQLAlchemy, ActiveRecord, and
Doctrine that could fit wiht javascript?

The way I ended parsing our forms is using the name attribute of the
form elements.
<input name="person.name" ...>

The json is updated/built from parsing these "name" attributes.
Nothing fancy, but it is fast and easy.


On Jan 11, 5:09 pm, AJ ONeal <Alvin.ON...@gmail.com> wrote:
> When I first found PURE what I was looking for was something to the effect
> of an ORM for Javascript (I'm a fan of SQLAlchemy, ActiveRecord, and
> Doctrine) but using JSON instead of a database.
>
> However, I'd also like to go in reverse, give a directive and get the data
> from a collection of nodes (mostly forms).
>
> Are there any plans add this kind of feature to PURE?
> I know that there's a storage specification for HTML5. I haven't looked into
> it enough yet, but I assume it could store json or will be sqlite-ish and
> hence this would be a very useful feature.
>
> AJ ONeal
> (317) 426-6525

--
You received this message because you are subscribed to the Google Groups "JavaScript Templates Engine PURE" group.
To post to this group, send email to Pure-Unobtrusive...@googlegroups.com.
To unsubscribe from this group, send email to Pure-Unobtrusive-Rende...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/Pure-Unobtrusive-Rendering-Engine?hl=en.




Mic (BeeBole)

unread,
Jan 13, 2010, 12:07:31 PM1/13/10
to JavaScript Templates Engine PURE

On Jan 12, 7:59 pm, AJ ONeal <coola...@gmail.com> wrote:
> I've considered this idea:
> <input name="person.name" ...>
>
> But it needs to be like this:
> <input name="person[name]" ...>
> or this
> <input name="people[][name]" ...>
>
> because that's what PHP, Ruby, Python, etc expect it to be.

I didn't know there was already a kind of cross language convention,
thanks.

>
> I don't have a firm understanding of many Design Patterns yet, but I'm
> forming some ideas on a variation of a Dual-MVC which I call DoubleDIP
> (Data-Interface-Presenter) from what I've learned with the various ORMs I've
> dabbled with.
>
> Transport Model - (JSON) - a hash, the properties of which probably map 1:1
> with the Class, which transmit in plain text when traversing systems
>
> Class - (Javascript Classes ) - manipulates the model
> Mapper - (jQuery.jStore) - maps the Model hash (or Class) to the DataStore
> DataStore - (DOM, LocalStorage, Cookies, Flash) - SQL, NoSQL, whatever.
> (HTML5 localstorage uses a NoSQL key/value store with a SQL backend... which
> is interesting because many SQL engines use key/value store backends such as
> BerkleyDB)
>
> Controller - (jQuery) - The application code itself
>
> Presenter - (PURE) - That which the Controller uses to map the Model to the
> View (and Ideally, can go in reverse as well)
> Template - (PURE directive) - The Presenter is to the Template what the
> Mapper is to the DataStore.
> View - (HTML) - What the user interacts with
>
> * Javascript is tricky because it has three DataStores. In HTML5 in has
> LocalStorage and, as always, it has the Web Service and the DOM.

Yep, and you have always to choose which one to use for an action.
But with V8 and initiatives like node.js, I think javascript will
become even more interesting, as the frontend and backend will share
the same language and is a scripting language.

However,
> the mapper can be configured to read from any or multiple of the three of
> these on a per-class basis. For some classes localStorage is a cache, for
> other classes localStorage may be the sole storage of the data (perhaps the
> Web Service only does processing, or some data must legally remain private).

I don't know how the security is handled while offline, is there
something planned for the HTML5 data storage access?

>
> This pattern focuses on the idea of mutual exclusion between a Web Service
> is its own deal and a Client application is its own deal and the two never
> cross barriers except where the Presenter of the one becomes the Data of the
> other. (Whereas every Web Service I've presently seen - Flickr, for example
> - has two APIs: one for internal use, the other for external use.

It looks you see it more like a web app(html, js, css), that runs
locally and has a kind of "save as" or sync to the web?
It depends on the kind of app you want to build.
In our case(a business app) a local storage is ok to provide a backup
usage when offline.
But then while online you synchronise and switch to use live data.
The trend is clearly going to a wider collaboration, and you need to
be online for that.
And you can't really skip the backend as it handles the security(no
security client side) and usually the business logic.

>
> The goal of my 'DoubleDIP' pattern is that I can go 'File -> Save As' on the
> webpage, and then open it from the desktop and it still has all of the same
> data, is still logged in, and functions the same as it did before.

Do you have an example of app you'd want to build?

>
> Additionally, I think that this design pattern can circumvent some licensing
> restrictions and patents, as the data always remains a distinct entity
> regardless of how it is processed on either end.

I don't get it, who's patents and licenses are you thinking of?

>
> Anyway, those are some semi-off the cuff thoughts, perhaps premature.

This topic of reversing came already few times on this forum and
emails I received.
I'm sure there is something to do, but so far, I didn't find a rather
generic and simple way to perform it.
And it was the main reason I "pluginized" PURE to allow people to
build blocks around it.

Soon or later, we'll need for our app an offline/online mechanism
ideally with html/js/css.
I'm interested to continue discussing the subject ;)

Cheers,

PS:For the other post yesterday, I was Chloé (my girlfriend who used
my computer to check her mail) ;)

AJ ONeal

unread,
Jan 16, 2010, 12:48:21 PM1/16/10
to pure-unobtrusive...@googlegroups.com
I've been meaning to get back to this.
 

> <input name="people[][name]" ...>

I didn't know there was already a kind of cross language convention,
thanks.


I'm not 100% sure about django and pylons. I just did a quick search and it seems that they generally don't use 'model[attr]', the just use 'attr'. I didn't see an example showing a nested model or an array.

However, PHP and Ruby on Rails definitely use that convention.
 

Yep, and you have always to choose which one to use for an action.
But with V8 and initiatives like node.js, I think javascript will
become even more interesting, as the frontend and backend will share
the same language and is a scripting language.

I'm also interested in BrowserPlus (Yahoo's cross-browser, cross-platform implementation of ActiveX). As soon as they have a working Linux plugin for Firefox or Chrome I think it's worthwhile to begin using. Imagine image and video manipulation using ruby or python in the client-side browser. The big disadvantage is that I doubt the user will be able to see the code since it is probably byte-compiled.
 

I don't know how the security is handled while offline, is there
something planned for the HTML5 data storage access?


Thinking in terms of the application being something that only 'updates' (using manifest files and such) to newer versions rather being 'visited' every time you access it in the browser, you can write your own client applications and ensure that they don't upload local data.

If you want to backup the data, you could sync the local store over https or however you choose.

You don't have to worry about cross-site scripting if you're using native JSON or if you strip any <script> tags from XML. The whole application is based on cross-site resource sharing.

Another thing, is that with BrowserPlus (and this is going to be the trend, I predict) you can connect to another browser and share files and web applications in a P2P manner.

Think NoSQL "eventually consistent" wikis in an office environment. 
 
Do you have an example of app you'd want to build?


I have a very small project I'm working on right now to help me explore HTTP and webservices.
WhatSayYe.com

Then end goal is a webservice that anyone can write a client for and that can be easily adapted to the iPhone, Andriod, Facebook, and other services and devices.
 
> Additionally, I think that this design pattern can circumvent some licensing
> restrictions and patents, as the data always remains a distinct entity
> regardless of how it is processed on either end.

I don't get it, who's patents and licenses are you thinking of?

Licensing is an issue. I'm not sure how the GPL applies to javascript, but in the desktop application world there's a lot of "the GPL virus" running amuck.

Mutagen is a great example. There's recently been some talk on the list of people who want to use mutagen, but don't want to keep their business logic proprietary and so they opt for something else. I suppose python's byte-compiling counts as linking and hence makes using mutagen in a proprietary product cumbersome. If mutagen had a presentation layer this wouldn't be an issue and it would encourage contribution. 

More businesses would use mutagen because they wouldn't have to link to it (hence being 'infected' by the GPL) or  write their own wrapper.

It would be trivial to contribute to mutagen because any extensions to it would be without the realm of proprietary business logic and would be 'safe' to release open-source.

After having called the GPL a virus, I do want to clarify that I like the GPL and I like that it encourages co-operation and discourages competition - you can please your customers (particularly the ones who are the tech savvy that share with friends, write themes, file bugs) and ward off competition.


The next example (patents) is Blackboard. Blackboard has a patent on something to the effect of "distributing information which is educational in nature over a collection of nodes" and a diagram depicting the internet, but labeled such that it somehow go through patent review.

With an architecture where each component is a web service and distinctly productive on its own I don't think Blackboard could sue someone (which is how they've defeated their competitors up to now - suing them or buying them out) who ties such 'arbitrary' services together that 'happen' to push information which is educational in nature across many nodes.
 
That's my big project goal. WhatSayYe will grow and take another domain as a simple survey site. Then it will grow again and become a test generator, on a simple testing site, then it will reach maturity as the 'quiz' module in Edumacate, a project which I've only conceptualized and drawn out on paper.

 
This topic of reversing came already few times on this forum and
emails I received.
I'm sure there is something to do, but so far, I didn't find a rather
generic and simple way to perform it.

I'd say think of it as a scraper. I don't think there should be any need for functions; so slightly 'dumber' directives. So not necessarily a 1:1 reversal.

Obviously, if you've got calculated values from functions you can't get back the original data sets, but then why would you need to? The purpose would be to get user input and changes.

AJ ONeal

p.s. Perhaps this would be better split into a few messages as its become somewhat eclectic.

Mic (BeeBole)

unread,
Feb 3, 2010, 11:08:27 AM2/3/10
to JavaScript Templates Engine PURE

If you google on "blackboard patents invalidated" there seems to be
plainty of
them.

>
> That's my big project goal. WhatSayYe will grow and take another domain as a
> simple survey site. Then it will grow again and become a test generator, on
> a simple testing site, then it will reach maturity as the 'quiz' module in
> Edumacate, a project which I've only conceptualized and drawn out on paper.

Is there any of them already visible somewhere online?
I lost you on this ;)

>
> > This topic of reversing came already few times on this forum and
> > emails I received.
> > I'm sure there is something to do, but so far, I didn't find a rather
> > generic and simple way to perform it.
>
> I'd say think of it as a scraper. I don't think there should be any need for
> functions; so slightly 'dumber' directives. So not necessarily a 1:1
> reversal.
>
> Obviously, if you've got calculated values from functions you can't get back
> the original data sets, but then why would you need to? The purpose would be
> to get user input and changes.

Imagine just a function to convert a currency to a local format.
If you want to parse it back you need an inverse function and the
troubles start.

>
> AJ ONeal
>
> p.s. Perhaps this would be better split into a few messages as its become
> somewhat eclectic.

Yep, when things get too long, better start a new thread |-)
Cheers,

Reply all
Reply to author
Forward
0 new messages