/// <summary> /// Delete attribute of base item before base item is deleted /// </summary> /// <param name="item">Base item about to be deleted</param> public void OnItemDelete(Item item) { if (item.HasData <JavascriptItemData>()) { var data = item.GetData <JavascriptItemData>(); JavascriptItemDataRepo.Delete(data); } }
/// <summary> /// Append attribute to base item when it is loaded /// </summary> /// <param name="item">Base item about to be persisted to datastore</param> public void OnItemUpdate(Item item) { if (item.HasData <JavascriptItemData>()) { var data = item.GetData <JavascriptItemData>(); if (data.Id == Guid.Empty) { OnItemCreate(item); } else { data.ScriptFunctions = GetFunctionDeclarations(data.Script); JavascriptItemDataRepo.Update(data); } } else if (JavascriptItemDataRepo.Read(item) is JavascriptItemData data) { JavascriptItemDataRepo.Delete(data); } }