[ 78 posts ] Go to page Previous1 ... 3, 4, 5, 6, 7, 8 Next

Greg Hinch

YUI Contributor

  • Username: greghinch
  • Joined: Wed Jun 03, 2009 10:49 am
  • Posts: 73
  • Location: Fairfax, CA , USA
  • Twitter: greghinch
  • GitHub: ghinch
  • Gists: ghinch
  • IRC: gr-eg
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Thu Sep 23, 2010 9:09 pm
+0-
So I finally got some code together for how I'd like to see things head, and put it in a gist:

http://gist.github.com/593942

There are 3 files there, one for the Model, one for a QueryManager (still not sure I love that name but it's what I've come up with for now) and one showing how you might implement it with a table script (though I haven't finalized that script so I didn't include it for now).

First of all the Model, you define the same way you define any subclass of base, using the standard ATTRS map to define the members. There are a few utility methods on the Model class itself that are useful here, 2 of which are "reference" and "referenceMany", which allow you to create relationships between Models (in the example I have Books and Authors, and a Book has one Author). You use the reference methods (or any other parser) simply by adding a "setter" to the property, taking advantage of that functionality built into Attribute. I think I'll probably need to add some way of making the reference methods optionally be lazy and refer to a remote source, in case you don't want to load all kinds of data you might not need for every instance. You can also define RENDERERS and EDITORS (not yet implemented fully) which are indexed by the same key as the Attributes. I kind of would love to do away with RENDERERS and just use the "getter" property of an Attribute, but as far as I can tell this leaves you without a away to get the actual value in any way, so for now it needs to be separate. Finally every subclass of Model has a "members" class method which gives you an array of keys for the Model and its parents (unless they are marked as readOnly).

Model instances are fairly simple, they have "edit" and "render" methods which take a key and return the editor/rendered value for it, a "compare" method which lets you evaluate one model instance against another to see if they are equal (eg, they came from different sources), and a "toObject" method which returns a standard JS object which can then be further serialized into whatever format you'd prefer with another utility.

The QueryManager is defined into 2 parts right now, QueryManagerBase and QueryManagerLocal, and I still plan on adding a QueryManagerRemote. At its core, a QueryManager is designed to take a DataSource and a Model definition, execute queries to the source and return an ArrayList (gives you the each, some, etc. convenience methods) of instances of the Model. A QueryManagerLocal instance adds the ability to sort the data before putting it into an ArrayList, while the QueryManagerRemote will allow you to set params, serialize them into a query string, and make the request to the DataSource. Additionally, a Paginator widget would interface either directly (by taking it as an attribute) or indirectly (via events) with the QueryManager.

My goals throughout all of this are 1) reuse as much of YUI3's infrastructure as possible (take advantage of Attribute/State rather than writing Fields, FieldDefs, etc. which reproduce this functionality) 2) develop only a base amount of functionality as would be necessary to model data for use in widgets (I'd rather see this toolset come in at 60-80% of what people need and get added to rather than too much and have to find a way to deprecate/move functionality) 3) take all of the interaction with queries, sorting, and pagination out of DataTable so that it is left to do just one thing: render tables (the rest of that is just as useful to a number of other widget types which shouldn't need to load any of DataTable to do the rest).

I know this is probably quite a bit different than what you guys are coming up with, so I hope we can find some common ground and go from there.

Matt Parker

YUI Contributor

  • Username: mattatlamplight
  • Joined: Mon Apr 20, 2009 12:03 pm
  • Posts: 465
  • Location: London UK
  • GitHub: mattparker
  • Gists: mattparker
  • Offline
  • Profile
Tags:

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Fri Sep 24, 2010 12:20 am
+0-
Hi Greg,

I'm sure no-one's going to disagree with your goals. Perhaps at some point fairly soon we ought to try and come up with a more definitive list of what 100% looks like, so that we know what 60-80% is. And make sure that the base is designed so that the other 20-40% can fairly easily be added.

I've only had a quick look at the Model bit so far - I'll have a look at it all properly, but a quick question/comment.

I think I quite like the idea of reference. But from what I can see, if you had two books by the same author, you'd end up with two instances of the same Author, one in each Book. Unless I've missed something, that would worry me a bit.

Also, I don't know what to think about Fields, and the different ways we've come up with dealing with them. I suppose I plump for a separate Field instance so that all the attributes of that field are in one place, rather than split between ATTR and RENDERERS and EDITORS etc. But then I worry a bit that a Field class extended Base is overkill.

Hmmm....

Matt

Greg Hinch

YUI Contributor

  • Username: greghinch
  • Joined: Wed Jun 03, 2009 10:49 am
  • Posts: 73
  • Location: Fairfax, CA , USA
  • Twitter: greghinch
  • GitHub: ghinch
  • Gists: ghinch
  • IRC: gr-eg
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Fri Sep 24, 2010 8:03 am
+0-
I agree its tough to know how to partition everything. Honestly, like I mentioned I'd love to just use the Attribute "getter" property rather than a separate RENDERERS hash, if Attribute were modified to allow a way to bypass a getter and just get the raw data I think that I would go that way. As it stand I don't see one, which means that the raw data is hidden once you define a getter. As far as EDITORS goes, I'm still not convinced that belongs on the Model either; most SS frameworks seem to take the path of defining a separate Form module, which may be a better option here.

The reference methods I defined I agree have some pitfalls, as you mentioned you could end up with multiple copies of the same data (though this is as much a problem with how data is serialized between the server and JS as anything, you'd end up with that problem even if you just used raw data), and even worse it can quickly become an infinite loop, for example if I just change Author to look like this:

Code:
var Author = Y.Base.create('author', Y.Model, [], {
}, {
  ATTRS : {
    surname : {},
    firstname : {},
    titles : Model.referenceMany(Book)
  }
});


Now the nice thing about using the "getter" functionality of Attribute is that it's lazy; until you call myInstance.get('attr') for the first time, the getter method hasn't fired and the value in memory is just the raw data. To further help this, I thought of making reference lazy as well (lazier? :) ). This would first entail adding a PRIMARY_KEY (as Satyam suggested) to the Model definition, which would point to some attribute on the model to use as a unique identifier. The Model would then use that key in a hash on the constructor to store a reference to each instance built (just references so no additional memory/code is affecting performance). Then rather than pass the entire data blob to construct reference properties, just pass their primary key, and reference can just do a lookup on the supplied constructor's hash. This would also require some way of then executing a fetch to the server if the data for the given key doesn't exist.

All that being said, I think the reference stuff may violate that 60% rule I was striving for. I just thought it was a cool idea and hopefully we can make something come of it. I don't know if we can necessarily define what 100% is at this time; I think the goal should be to define at a bare minimum what would be required (even if it puts a little more work than desired into the implementors for now), try creating a few Widgets based on it (I'd like to see a DataTable, a List, and a Form at least), and see where the common pain points are.

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Sat Sep 25, 2010 2:44 pm
+0-
I wonder if we are having the largest number of posts on a single thread in the forum. At least I'm sure we have the record for nonsensical subject lines.

I might try to go on adding some features, but I think I have most of what I wanted to show on my demo at:

http://www.satyam.com.ar/yui/3.0.0/recordTest.html

It is a real YUITest case so the object being tested is really working. I know of a bug which I patched by cheating and probably many others which I'm unaware of, but basically, what is there it works.

I suggest looking at the form and the explanation right below. Yes, it is a paging control over that form, and it works. You can move back and forth and you can modify any field in any record, move elsewhere and return and the modified field will remain modified. The Serialize button will activate on 'dirty' records. If you click on it, the whole RecordSet will be serialized in JSON format right below the form. Only the modified fields and the primary key are included in the serialization, which is the default. There are XML, URL-encoded and JSOn serializers and you have the option of serializing everything or 'dirty-only' fields (plus primary key).

I explained how it is used and commented on the code that makes the form, it doesn't require too much. Both the data and the RecordSet field definitions are the same as used in the table right above. Note the nesting of the data in both.

All the object being tested is in a single file, which is absolute nonsense, I know, but it just grew that way and, anyway, the packaging of the different components is not something I was concerned with at this point.

Matt Parker

YUI Contributor

  • Username: mattatlamplight
  • Joined: Mon Apr 20, 2009 12:03 pm
  • Posts: 465
  • Location: London UK
  • GitHub: mattparker
  • Gists: mattparker
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Mon Sep 27, 2010 10:19 am
+0-
Hi,

this is the sort of idea I was thinking with index plugins. Obviously there's more - they need to update themselves when records are added/removed, but the point is that the base filter/sort ought to check if the index exists. I suppose a RecordSetIndexBase could listen for and cancel host methods, but I don't know what the overhead of that is compared to the extra kb/hassle of supporting indexes directly...

Anyway, here it is:
http://gist.github.com/599527

Matt

Luke Smith

YUI Contributor

  • Username: lsmith
  • Joined: Thu Aug 28, 2008 7:50 am
  • Posts: 507
  • Location: Sunnyvale
  • Twitter: ls_n
  • GitHub: lsmith
  • Gists: lsmith
  • IRC: ls_n
  • YUI Developer
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Mon Sep 27, 2010 12:20 pm
+0-
Matt,

I completely forgot to update the thread on this, but the 404 links to Satyam's slides have been fixed. That is, I moved stuff where the links would now correctly resolve. Oooops!

Thanks for catching that.

Luke Smith

YUI Contributor

  • Username: lsmith
  • Joined: Thu Aug 28, 2008 7:50 am
  • Posts: 507
  • Location: Sunnyvale
  • Twitter: ls_n
  • GitHub: lsmith
  • Gists: lsmith
  • IRC: ls_n
  • YUI Developer
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Mon Sep 27, 2010 12:22 pm
+0-
Satyam,

If you want to move the discussion to a new, more appropriately titled, thread, you're welcome to. There's a pretty good chance the others on the thread would follow :)

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Mon Sep 27, 2010 1:23 pm
+0-
I like silly records, this is the 58th message under this subject. Isn't it ... great? Possibly not, never mind.

Matt Parker

YUI Contributor

  • Username: mattatlamplight
  • Joined: Mon Apr 20, 2009 12:03 pm
  • Posts: 465
  • Location: London UK
  • GitHub: mattparker
  • Gists: mattparker
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Mon Sep 27, 2010 2:02 pm
+0-
Greg,

I had a bit of a thought about reference(). It involves RecordSets though!

Rather than (or perhaps as well as) telling the concrete Book instance who the Author instance is, could you have a reference at the 'table' level, so:
Code:
fields: {
 authorid: {
   refRecordSet: myAuthorRecordSet,
   refField: "id"
 },
 //... etc
}

sort of thing?

Matt

Tilo Mitra

YUI Developer

  • Username: tilomitra
  • Joined: Tue Mar 16, 2010 7:30 am
  • Posts: 12
  • Location: Sunnyvale
  • Twitter: tilomitra
  • GitHub: tilomitra
  • Gists: tilomitra
  • IRC: tilomitra
  • YUI Developer
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Mon Sep 27, 2010 4:56 pm
+0-
Hey everyone,

As a follow-up of today's meeting, we spent part of the afternoon trying to decide how best to store fields (such as readonly) that are associated to keys. There are two trains of thought here - they can either be stored on the Record instance, or on the Recordset. We have mulled over this for a while and preferred to have this information stored on the Recordset.

In doing so, a plugin can be made for recordset that allows these fields to be implemented and overwrites the add/remove (and probably other) methods to account for any change in logic (ie: if readonly, don't remove). The consensus amongst the group internally was that storing this information on individual records would be too granular.

However, we wanted to get this out on to the forums for discussion, so feel free to give your inputs on this.
  [ 78 posts ] Go to page Previous1 ... 3, 4, 5, 6, 7, 8 Next
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum