Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
ws
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiefu committed Apr 11, 2014
1 parent e1b9af2 commit 831e43e
Showing 1 changed file with 78 additions and 81 deletions.
159 changes: 78 additions & 81 deletions core-meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
-->

<!--
`core-meta` provides a method of constructing a self-organizing database.
It is useful to collate element meta-data for things like catalogs and for
designer.
Expand Down Expand Up @@ -59,90 +58,88 @@
<link rel="import" href="../polymer/polymer.html">

<polymer-element name="core-meta" attributes="list label type">
<script>

<script>

(function() {
(function() {

var SKIP_ID = 'meta';
var metaData = {}, metaArray = {};

Polymer('core-meta', {

var SKIP_ID = 'meta';
var metaData = {}, metaArray = {};

Polymer('core-meta', {

/**
* The type of meta-data. All meta-data with the same type with be
* stored together.
*
* @attribute type
* @type string
* @default 'default'
*/
type: 'default',

alwaysPrepare: true,

ready: function() {
this.register(this.id);
},

get metaArray() {
var t = this.type;
if (!metaArray[t]) {
metaArray[t] = [];
}
return metaArray[t];
},

get metaData() {
var t = this.type;
if (!metaData[t]) {
metaData[t] = {};
}
return metaData[t];
},

register: function(id, old) {
if (id && id !== SKIP_ID) {
this.unregister(this, old);
this.metaData[id] = this;
this.metaArray.push(this);
}
},

unregister: function(meta, id) {
delete this.metaData[id || meta.id];
var i = this.metaArray.indexOf(meta);
if (i >= 0) {
this.metaArray.splice(i, 1);
}
},

/**
* Returns a list of all meta-data elements with the same type.
*
* @attribute list
* @type array
* @default []
*/
get list() {
return this.metaArray;
},

/**
* Retrieves meta-data by ID.
*
* @method byId
* @param {String} id The ID of the meta-data to be returned.
* @returns Returns meta-data.
*/
byId: function(id) {
return this.metaData[id];
/**
* The type of meta-data. All meta-data with the same type with be
* stored together.
*
* @attribute type
* @type string
* @default 'default'
*/
type: 'default',

alwaysPrepare: true,

ready: function() {
this.register(this.id);
},

get metaArray() {
var t = this.type;
if (!metaArray[t]) {
metaArray[t] = [];
}

});
return metaArray[t];
},

get metaData() {
var t = this.type;
if (!metaData[t]) {
metaData[t] = {};
}
return metaData[t];
},

register: function(id, old) {
if (id && id !== SKIP_ID) {
this.unregister(this, old);
this.metaData[id] = this;
this.metaArray.push(this);
}
},

unregister: function(meta, id) {
delete this.metaData[id || meta.id];
var i = this.metaArray.indexOf(meta);
if (i >= 0) {
this.metaArray.splice(i, 1);
}
},

/**
* Returns a list of all meta-data elements with the same type.
*
* @attribute list
* @type array
* @default []
*/
get list() {
return this.metaArray;
},

/**
* Retrieves meta-data by ID.
*
* @method byId
* @param {String} id The ID of the meta-data to be returned.
* @returns Returns meta-data.
*/
byId: function(id) {
return this.metaData[id];
}

})();
});

</script>
})();

</script>
</polymer-element>

0 comments on commit 831e43e

Please sign in to comment.