private void UpdateImplementation(TContext context, IShadow <TItem> shadow, TElement current, TElement next) { OnBeforeUpdate(context, shadow, current, next); // let the inherited elements update first var startTransactionsCount = Transaction.Current.Count; // perform the main update (!), which allows user code to update... Update(context, shadow, current, next); // get total number of transactions that occured var noTransactions = Transaction.Current.Count - startTransactionsCount; var c = ElementValue.From(current, current?.Attributes); var n = ElementValue.From(next, next?.Attributes); // update those attributes which are defined at 'this level' UpdateLocalAttributes(context, shadow, c, n); // if have any transactions trigger the callback, if a callback has been defined of course! if (noTransactions > 0) { var action = shadow.State.Get <Action <BasePrimitive, IShadow> >(UpdatedStateKey); if (action != null) { Transaction.Current.Add(() => { action(current, shadow); }); } } // and finally ... OnAfterUpdate(context, shadow, current, next); }
/// <summary> /// Update our three key attributes. /// </summary> /// <param name="context"></param> /// <param name="shadow"></param> /// <param name="current"></param> /// <param name="next"></param> private void UpdateLocalAttributes(TContext context, IShadow <TItem> shadow, ElementValue <TElement> current, ElementValue <TElement> next) { StandardAttributes.CreatedAttribute.Update(current, next, context, shadow, (s, component, createFunc) => { createFunc(component, s); }); StandardAttributes.RefAttribute.Update(current, next, context, shadow, (s, component, viewRef) => { viewRef.Set(s.Item); }); StandardAttributes.UpdatedAttribute.Update(current, next, context, shadow, (s, component, action) => { s.State.Set <Action <BasePrimitive, IShadow> >(UpdatedStateKey, action); }, (s, component, c, n) => { s.State.Set <Action <BasePrimitive, IShadow> >(UpdatedStateKey, n); }, (s, component, c) => { s.State.Delete <Action <BasePrimitive, IShadow> >(UpdatedStateKey); }); }