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AAY,GAAO,IAAY,EAAU,CAAC,IAAI,GAAO,CAC7D,IAAK,EAAK,SAAU,EAAU,MAAO,GAG3C,GAAG,OAEE,GAAU,GACb,KAAK,KAAK,SAAU,EACxB,EAKA,MAAO,SAAe,GACpB,KAAK,MAAM,OAAO,KAAK,KAAK,YAAa,EAC3C,EAEA,QAAS,SAAiB,IACvB,KAAK,YAAY,MAAQ,KAAK,MAAM,SAAU,KAAM,EACvD,EAUA,OAAQ,WACN,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,YACxC,GAGF","file":"/npm/models@0.2.0/models.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/models@0.2.0/models.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/* vim:set ts=2 sw=2 sts=2 expandtab */\n/*jshint undef: true es5: true node: true devel: true\n         forin: true, eqnull: true */\n/*global define: true */\n\n(typeof define === \"undefined\" ? function ($) { $(require, exports, module); } : define)(function (require, exports, module, undefined) {\n\n\"use strict\";\n\nvar EventEmitter = require('!raw.github.com/Gozala/events/v0.4.0/events').EventEmitter;\n\nexports.version = \"0.1.0\";\n\nvar isArray = Array.isArray;\nfunction isFunction(value) { return typeof value === \"function\"; }\nfunction getOwnPropertyDescriptors(object) {\n  var descriptors = {};\n  Object.getOwnPropertyNames(object).forEach(function(name) {\n    descriptors[name] = Object.getOwnPropertyDescriptor(object, name);\n  });\n  return descriptors;\n}\nfunction extend(target) {\n  Array.prototype.forEach.call(arguments, function(source) {\n    if (source !== target)\n      Object.defineProperties(target, getOwnPropertyDescriptors(source));\n  });\n  return target;\n}\n\nexports.Model = EventEmitter.extend({\n  constructor: function Model(attributes, options) {\n    if (!(this instanceof Model))\n      return new Model(attributes, options);\n\n    attributes = attributes || {};\n    var defaults = this.defaults;\n    if (defaults) {\n      if (isFunction(defaults))\n        defaults = defaults();\n      attributes = extend({}, defaults, attributes);\n    }\n    this.attributes = {};\n    this.set(attributes, { silent : true });\n    if (options && 'collection' in options && options.collection)\n      this.collection = options.collection;\n    this.initialize(attributes, options);\n  },\n  isModel: true,\n  isNew: function isNew() {\n    return !this.id;\n  },\n  /**\n   * The attributes property is the internal hash containing the model's state.\n   * Please use set to update the attributes instead of modifying them\n   * directly. If you'd like to retrieve and munge a copy of the model's\n   * attributes, use `toJSON` instead.\n   */\n  attributes: null,\n  /**\n   * The defaults hash can be used to specify the default attributes for your\n   * model. When creating an instance of the model, any unspecified attributes\n   * will be set to their default value.\n   */\n  defaults: null,\n  /**\n   * A special property of models, the id is an arbitrary string (integer id\n   * or UUID). If you set the id in the attributes hash, it will be copied onto\n   * the model as a direct property. Models can be retrieved by id from\n   * collections.\n   */\n  id: null,\n  /**\n   * Attribute name that is mapped to an `id` property of this model. Analog to\n   * primary key in DB.\n   */\n  '@' : 'id',\n  /**\n   * Initialize is an empty function by default. Override it with your own\n   * initialization logic.\n   * @param {Object} attributes\n   * @param {Object} options\n   */\n  initialize : function initialize(attributes, options) { return this; },\n  /**\n   * Consumer must implement custom validation logic in this method. Method is\n   * called by a `set`, and is passed the attributes that are about to be\n   * updated. If the model and attributes are valid, don't return anything from\n   * validate. If the attributes are invalid, throw an Error of your choice. It\n   * can be as simple `Error` with an error message to be displayed, or a\n   * complete error object that describes the error programmatically. `set` and\n   * save will not continue if validate returns an error.\n   * Failed validations trigger an \"error\" event.\n   * @param {Object} attributes\n   *    Map of key values that needs to be validated before they are set.\n   */\n  validate: function validate(attributes) { return attributes; },\n  prase: function parse(data) { return data; },\n    // Returns `true` if the attribute contains a value that is not null\n  // or undefined.\n  has: function(attr) {\n    return this.attributes[attr] != null;\n  },\n\n  /**\n   * Get the current value of an attribute from the model.\n   */\n  get: function get(key) {\n    return this.attributes[key];\n  },\n  /**\n   * Set a hash of attributes (one or many) on the model. If any of the\n   * attributes change the models state, a \"change\" event will be triggered,\n   * unless {silent: true} is passed as an option. Change events for specific\n   * attributes are also triggered, and you can bind to those as well, for\n   * example change:title, and change:content.\n   */\n  set: function set(attributes, options) {\n    var changes, silent, id;\n    // Validate all the attributes using internal validation mechanism. If\n    // new attributes are returned that means that values were formated or\n    // overridden by a validator.\n    attributes = attributes.isModel ? attributes.attributes : attributes;\n    attributes = this.validate(attributes);\n\n    silent = options && options.silent;\n\n    // Check for changes of `id`.\n    if ((id = attributes[this['@']]))\n      this.id = id;\n\n    Object.keys(attributes).forEach(function(key) {\n      var previous = this.attributes[key];\n      var value = this.attributes[key] = attributes[key];\n\n      if (!silent && previous !== value) {\n        this.emit(\"change:\" + key, ((changes || (changes = {}))[key] = {\n          key: key, previous: previous, value: value\n        }), this, options);\n      }\n    }, this);\n\n    if (!silent && changes)\n      this.emit(\"change\", changes, this, options);\n\n    return this;\n  },\n\n  clone: function clone() {\n    return new this.constructor(this);\n  },\n\n  save: function save(attributes, options) {\n    options = options || {};\n    if (attributes)\n      this.set(attributes, options);\n    var action = this.isNew() ? \"create\" : \"update\";\n    (this.constructor.sync || this.sync)(action, this, options);\n  },\n\n  fetch: function fetch(options) {\n    options = options || {};\n    var model = this;\n    var success = options.success;\n    options.success = function(response) {\n      model.set(model.parse(response), options);\n      if (success) success(model, response);\n    };\n    \n    (this.constructor.sync || this.sync)(\"read\", this, options);\n  },\n\n  /**\n   * Remove an attribute by deleting it from the internal attributes hash.\n   * Fires a \"change\" event unless silent is passed as an option.\n   */\n  unset: function unset(attributes, options) {\n    var changes, silent;\n\n    silent = options && options.silent;\n    (isArray(attributes) ? attributes : [attributes]).forEach(function(key) {\n      // Check for changes of `id`.\n      if (key === this['@'])\n        this.id = null;\n\n      var previous = this.attributes[key];\n      delete this.attributes[key];\n      var value = this.attributes[key];\n\n      if (!silent && previous !== value) {\n        this.emit(\"change:\" + key, ((changes || (changes = {}))[key] = {\n          key: key, previous: previous, value: value\n        }));\n      }\n    }, this);\n\n    if (!silent && changes)\n      this.emit(\"change\", changes);\n  },\n  /**\n   * Removes all attributes from the model. Fires a \"change\" event unless\n   * silent is passed as an option.\n   */\n  clear: function clear(options) {\n    this.unset(Object.keys(this.attributes), options);\n  },\n\n  destroy: function destroy(options) {\n    (this.constructor.sync || this.sync)(\"delete\", this, options);\n  },\n\n  /**\n   * Return a copy of the model's attributes for JSON stringification. This can\n   * be used for persistence, serialization, or for augmentation before being\n   * handed off to a view. The name of this method is a bit confusing, as it\n   * doesn't actually return a JSON string — but I'm afraid that it's the way\n   * that the [JavaScript API for JSON.stringify works]\n   * (https://developer.mozilla.org/en/JSON#toJSON()_method).\n   */\n  toJSON: function toJSON() {\n    return JSON.parse(JSON.stringify(this.attributes));\n  }\n});\n\n});\n"]}