public void Unset(string key, bool silent) { // Setup temporary copy of attributes to be assigned // to the previousAttributes register if a change occurs var prev = Clone(this.attributes); // Check that server data is present if (!HasDataFromServer) { this.OnNoData(key); return; } if (this.attributes [key] != null) { // Remove the specific element this.attributes.Remove(key); this.hasChanged = true; // Broadcasts an attribute specific change event of the form: // **change:attribute_name** if (!silent) { RoarManager.OnComponentChange(this.name); } } // Broadcasts a `change` event if the model changed if (HasChanged && !silent) { this.previousAttributes = prev; this.Change(); } }
// Removes all attributes from the model public void Clear(bool silent) { attributes = new Dictionary <string, CT> (); // Set internal changed flag this.hasChanged = true; if (!silent) { RoarManager.OnComponentChange(name); } }
//TODO: This should probably be called "Add" as it seems to // update/add to the model rather than replace all the entries. public DataModel <CT, DT> Set(Dictionary <string, CT> data, bool silent) { string changedProp; // Setup temporary copy of attributes to be assigned // to the previousAttributes register if a change occurs Dictionary <string, CT> prev = Clone(this.attributes); // Reset the internal register attributes = new Dictionary <string, CT> (); foreach (string propKey in data.Keys) { this.attributes [propKey] = data[propKey]; if (!prev.ContainsKey(propKey) || (!Comparer <CT> .Equals(prev[propKey], data[propKey]))) { this.hasChanged = true; changedProp = propKey; RoarManager.OnComponentAttributeChange(this.name, changedProp); } } if (hasChanged) { if (!silent) { RoarManager.OnComponentChange(this.name); } } // Broadcasts a `change` event if the model changed if (HasChanged && !silent) { this.previousAttributes = prev; this.Change(); } return(this); }
// Manually fires a "change" event on this model public void Change() { RoarManager.OnComponentChange(this.name); this.hasChanged = false; }