Created
December 11, 2009 18:38
-
-
Save kapilt/254404 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
ideal for a data format agnostic, schema consuming component | |
*/ | |
var MySchema = new Y.DataSchema.JSON({'metaFields':{jobId: "jobId", totalRecords:"totalRecords"}}) | |
var new Y.SchemaConsumer({schema:MySchema}) | |
Y.SchemaConsumer.process( data ); | |
Y.SchemaConsumer.process = function(data) { | |
return this.get("schema").parse(data); | |
} | |
/* | |
current, currently we have to force a user & implementor of such a schema consumer component to pass | |
additional fields or force the implementor to create N encapsulations. | |
*/ | |
var MySchema = {'metaFields':{jobId: "jobId", totalRecords:"totalRecords"}} | |
var new Y.SchemaConsumer({schema:MySchema, schema_type:Y.DataSchema.JSON.apply}) | |
Y.SchemaConsumer.process = function(data) { | |
var schema = this.get("schema"); | |
var schema_type = this.get("schema_type"); | |
return schema_type(schema); | |
} | |
/* | |
i think the multiplicity of dataschema plugins for a datasource is a good example of the sort of behavior | |
i'm trying to avoid. If the schema was an object that encapsulated its method, you could just have a generic | |
dataschemaplugin and pass it a dataschema instead of having to create numerous plugins, or passing an extra | |
schema apply function. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment