Beispiel #1
0
        private ObservableObject(object target,
                                 IDictionary <string, object> values,
                                 Func <IObservableObject <T, W>, T> proxify, string name = null,
                                 IManipulator <W, object> manipulator = null, object meta = null, params Type[] otherTypes)
        {
            if (!typeof(T).IsInterface)
            {
                throw new ArgumentException($"{typeof(T).Name} should be interface");
            }

            if (proxify == null)
            {
                throw new ArgumentException($"{nameof(proxify)} should not be Null");
            }

            Meta = meta;

            Target = target;

            Values = values ?? new Dictionary <string, object>();

            Name = name ?? $"ObservableObject@{States.NextId}";

            Manipulator = manipulator ?? Manipulator <W, object> .For();

            KeysAtom = new Atom($"{Name}.keys");

            Proxy = proxify(this);
        }
Beispiel #2
0
        public ObservableValue(TIn value, string name = null, IManipulator manipulator = null, object meta = null) : base(name ?? $"ObservableValue@{States.NextId}")
        {
            Meta = meta;

            Manipulator = manipulator ?? Manipulator <TIn, TOut> .For();

            _Value = Manipulator.Enhance(value, default(TIn), Name);
        }
Beispiel #3
0
        protected ObservableList(string name, IManipulator <TIn, TOut> manipulator = null, object meta = null)
        {
            Values = new List <TIn>();

            Name = name ?? $"ObservableArray@{States.NextId}";

            Manipulator = manipulator ?? Manipulator <TIn, TOut> .For();

            KeysAtom = new Atom(Name);

            Meta = meta;
        }
        protected ObservableMap(string name, IManipulator <TIn, TOut, TKey> manipulator = null, object meta = null)
        {
            Data = new Map <TKey, IObservableValue <TIn> >();

            HasMap = new Map <TKey, IObservableValue <bool> >();

            Name = name ?? $"ObservableMap@{States.NextId}";

            Manipulator = manipulator ?? Manipulator <TIn, TOut, TKey> .For();

            KeysAtom = new Atom($"{Name}.keys()");

            Meta = meta;
        }
Beispiel #5
0
        public bool PrepareNewValue(TIn oldValue, TIn changeValue, out TIn newValue)
        {
            this.CheckIfStateModificationsAreAllowed();

            newValue = changeValue;

            if (this.HasInterceptors <IValueWillChange <TIn> >())
            {
                var change = this.NotifyInterceptors(new ValueWillChange <TIn>(newValue, this));
                if (change == null)
                {
                    return(false);
                }
                newValue = change.NewValue;
            }

            newValue = (TIn)Manipulator.Enhance(newValue, oldValue, Name);

            return(!EqualityComparer <TIn> .Default.Equals(newValue, oldValue));
        }
 public TOut Get(TKey key)
 {
     return(Manipulator.Dehance(Has(key) ? (Data[key] as IValueReader <TIn>).Value : default(TIn)));
 }