Пример #1
0
        public void RemoveQuery(MediaQuery mediaQuery)
        {
            bool byMediaProperties(MediaQueryCache q) => q.Value.Media == mediaQuery.InternalMedia.Media;

            var cache = mediaQueries.Find(byMediaProperties);

            if (cache != null)
            {
                cache.MediaQueries.Remove(mediaQuery);
                if (cache.MediaQueries.Count() == 0)
                {
                    Js.InvokeVoidAsync($"{ns}.removeMediaQuery", DotNetInstance, mediaQuery.InternalMedia.Media);
                    mediaQueries.Remove(cache);
                }
            }
        }
Пример #2
0
        public void AddQuery(MediaQuery newMediaQuery)
        {
            bool byMediaProperties(MediaQueryCache q) => q.MediaRequested == newMediaQuery.Media;

            var cache = mediaQueries.Find(byMediaProperties);

            if (cache == null)
            {
                cache = new MediaQueryCache
                {
                    MediaRequested = newMediaQuery.Media,
                };
                mediaQueries.Add(cache);
            }
            cache.MediaQueries.Add(newMediaQuery);
        }
Пример #3
0
        public async Task Initialize(MediaQuery mediaQuery)
        {
            if (mediaQuery?.Media == null)
            {
                return;
            }
            var cache = GetMediaQueryFromCache(byMedia: mediaQuery.Media);

            if (cache == null)
            {
                return;
            }

            if (cache.Value == null)
            {
                // If we don't flag the cache as loading, duplicate requests will be sent async.
                // Duplicate requests = poor performance, esp with web sockets.
                if (!cache.Loading)
                {
                    cache.Loading = true;

                    var module = await moduleTask.Value;
                    var task   = module.InvokeAsync <MediaQueryArgs>($"addMediaQueryToList", DotNetInstance, cache.MediaRequested);
                    cache.Value   = await task;
                    cache.Loading = task.IsCompleted;
                    // When loading is complete dispatch an update to all subscribers.
                    foreach (var item in cache.MediaQueries)
                    {
                        item.MediaQueryChanged(cache.Value);
                    }
                }
            }
            else
            {
                var module = await moduleTask.Value;
                var task   = module.InvokeAsync <MediaQueryArgs>($"getMediaQueryArgs", cache.MediaRequested);
                cache.Value = await task;

                mediaQuery.MediaQueryChanged(cache.Value);
            }
        }
Пример #4
0
        public async Task Initialize(MediaQuery mediaQuery)
        {
            bool byMediaProperties(MediaQueryCache q) => q.MediaRequested == mediaQuery.Media;

            var cache = mediaQueries.Find(byMediaProperties);

            if (cache.Value == null)
            {
                if (!cache.Loading)
                {
                    cache.Loading = true;
                    var task = Js.InvokeAsync <MediaQueryArgs>($"{ns}.addMediaQueryToList", DotNetInstance, cache.MediaRequested);
                    cache.Value   = await task;
                    cache.Loading = task.IsCompleted;
                    foreach (var item in cache.MediaQueries)
                    {
                        item.MediaQueryChanged(cache.Value);
                    }
                }
            }
        }
Пример #5
0
        public async Task RemoveQuery(MediaQuery mediaQuery)
        {
            if (mediaQuery == null)
            {
                return;
            }

            var cache = GetMediaQueryFromCache(byMedia: mediaQuery.Media);

            if (cache == null)
            {
                return;
            }

            cache.MediaQueries.Remove(mediaQuery);
            if (cache.MediaQueries.Any())
            {
                mediaQueries.Remove(cache);
                var module = await moduleTask.Value;
                await module.InvokeVoidAsync($"removeMediaQuery", DotNetInstance, mediaQuery.InternalMedia.Media);
            }
        }
 public async Task Initialize(MediaQuery mediaQuery) => await MqService.Initialize(mediaQuery);
 public async Task RemoveQuery(MediaQuery mediaQuery) => await MqService.RemoveQuery(mediaQuery);
 public void AddQuery(MediaQuery newMediaQuery) => MqService.AddQuery(newMediaQuery);