Beispiel #1
0
        /// <summary>
        /// ///
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="component"></param>
        /// <param name="model"></param>
        public void SetModel <TModel>(IStatefulContainer <TModel> component, TModel model)
        {
            // increment the mutation id first, very important
            var mutationId = Interlocked.Increment(ref _mutationId);

            // attempt to clone
            var finalModel = ObjectUtils.Clone(model, _cloneMode, _swallowCloneErrors);

            // and raise an event
            OnChanged(new ModelChange(component, finalModel, mutationId));
        }
Beispiel #2
0
        protected BaseContentPage()
        {
            Host = BuildHost.Create(this, (buildEnvironment, layoutContext) =>
            {
                var statefulContainer = CreateStateContainer(buildEnvironment);

                _statefulContainer = statefulContainer;

                Init(buildEnvironment);

                return(statefulContainer);
            });


            // now start the host
            Host.Start();
        }
Beispiel #3
0
 public DefaultLayoutHost(BuildHostInstance buildHostInstance, LayoutHostSettings settings = default) : base(buildHostInstance, settings)
 {
     _rootContainer = buildHostInstance.RootContainer;
 }
 /// <summary>
 /// Update the state of a <see cref="IStatefulContainer{TModel}"/> to a new value.
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <param name="component"></param>
 /// <param name="model"></param>
 public static void SetModel <TModel>(this IStatefulContainer <TModel> component, TModel model)
 {
     // Get the build owner of the component and update the value
     component.Context.Owner.SetModel(component, model);
 }
Beispiel #5
0
 public ModelChange(IStatefulContainer container, object model, int mutationId)
 {
     Container  = container;
     Model      = model;
     MutationId = mutationId;
 }
Beispiel #6
0
 /// <summary>
 /// Get the current mutation id for a stateful container
 /// </summary>
 /// <param name="stateContainer"></param>
 /// <returns></returns>
 public int GetMutationId(IStatefulContainer stateContainer)
 {
     return(_modelMap.TryGetValue(stateContainer.Context.Id, out var containerModel) ? containerModel.LastMutationId : MutationUnspecified);
 }
Beispiel #7
0
 /// <summary>
 /// Get the current model for a specified stateful container.
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <param name="component"></param>
 /// <returns></returns>
 public TModel GetModel <TModel>(IStatefulContainer <TModel> component)
 {
     return(ModelBag.Get(component));
 }