Skip to content

Instantly share code, notes, and snippets.

@kapilt
Created December 11, 2009 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kapilt/254404 to your computer and use it in GitHub Desktop.
Save kapilt/254404 to your computer and use it in GitHub Desktop.
/*
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