Exemple #1
0
 // Simple Action Wrapper
 private static void _handler <T>(T _)
 {
     foreach (var action in _actions.ToArray())
     {
         action(Syringe <T1> .Get(), Syringe <T2> .Get());
     }
 }
Exemple #2
0
        /// <summary>Fire <paramref name="action"/> every time <seealso cref="T1"/> or <seealso cref="T2"/> changes.</summary>
        public static void Subscribe(Action <T1, T2> action, bool getValuesNow = true)
        {
            // Trigger the Action When Any Value Was Set
            if (getValuesNow && (Syringe <T1> .HasValue() || Syringe <T2> .HasValue()))
            {
                action(Syringe <T1> .Get(), Syringe <T2> .Get());
            }

            // Add the Action
            _actions.Add(action);

            // Add the Listeners (when adding the first action)
            if (_actions.Count > 1)
            {
                return;
            }
            Syringe <T1> .Subscribe(_handler, false);

            Syringe <T2> .Subscribe(_handler, false);
        }