{"id":21518021,"url":"https://github.com/sidovsky/debouncemonitoring","last_synced_at":"2025-04-09T21:44:26.833Z","repository":{"id":143092720,"uuid":"345014833","full_name":"SIDOVSKY/DebounceMonitoring","owner":"SIDOVSKY","description":"📑 Add debounce logic for any method in a single line.","archived":false,"fork":false,"pushed_at":"2021-07-05T17:54:01.000Z","size":167,"stargazers_count":49,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-23T23:35:47.938Z","etag":null,"topics":["click","debounce","maui","mvvm","rx","throttle","touch","ui","uwp","winforms","wpf","xamarin"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SIDOVSKY.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-06T05:35:16.000Z","updated_at":"2025-02-24T12:24:05.000Z","dependencies_parsed_at":"2023-06-09T09:00:13.167Z","dependency_job_id":null,"html_url":"https://github.com/SIDOVSKY/DebounceMonitoring","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SIDOVSKY%2FDebounceMonitoring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SIDOVSKY%2FDebounceMonitoring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SIDOVSKY%2FDebounceMonitoring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SIDOVSKY%2FDebounceMonitoring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SIDOVSKY","download_url":"https://codeload.github.com/SIDOVSKY/DebounceMonitoring/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119417,"owners_count":21050754,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["click","debounce","maui","mvvm","rx","throttle","touch","ui","uwp","winforms","wpf","xamarin"],"created_at":"2024-11-24T00:46:15.292Z","updated_at":"2025-04-09T21:44:26.808Z","avatar_url":"https://github.com/SIDOVSKY.png","language":"C#","readme":"![LOGO](Assets/icon.png)\n\n# DebounceMonitoring\n\n[![CI](https://github.com/SIDOVSKY/DebounceMonitoring/actions/workflows/ci.yml/badge.svg)](https://github.com/SIDOVSKY/DebounceMonitoring/actions/workflows/ci.yml)\n[![PLATFORM](https://img.shields.io/badge/platform-.NET%20Standard%202.0-lightgrey)](#DebounceMonitoring)\n[![NuGet](https://img.shields.io/nuget/v/DebounceMonitoring?logo=nuget)](https://www.nuget.org/packages/DebounceMonitoring/)\n\nExtensions to filter out repeated function calls caused by false or accidental clicks or touches.\n* One-line integration\n* Inlined, no method wrapping\n* Shareable between multiple platforms\n* Automated testing friendly\n\n## Installing\n\nAdd [NuGet package](https://www.nuget.org/packages/DebounceMonitoring) to your [.NET Standard 2.0 - compatible](https://github.com/dotnet/standard/blob/master/docs/versions/netstandard2.0.md#platform-support) project\n\n```\nPM\u003e Install-Package DebounceMonitoring\n```\n\n## Usage\n\n```csharp\nusing DebounceMonitoring;\n```\n\n#### Debounce **instance** methods:\n```csharp\ninternal class ViewModel\n{\n    public void OnButtonClick()\n    {\n        if (this.DebounceHere()) return;\n\n        // Handle the click\n    }\n}\n```\n\u003csup\u003e[snippet source](/DebounceMonitoring.Tests/Snippets/Sample.cs#L9-L16)\u003c/sup\u003e\n\n#### Debounce **lambdas** and **local functions**:\n```csharp\npublic Command ClickCommand { get; }\n\npublic ViewModel()\n{\n    ClickCommand = new Command(() =\u003e\n    {\n        if (this.DebounceHere()) return;\n\n        // Handle the click\n    });\n}\n```\n\u003csup\u003e[snippet source](/DebounceMonitoring.Tests/Snippets/Sample.cs#L18-L28)\u003c/sup\u003e\n\n#### Debounce **static** methods:\n```csharp\ninternal class Analytics\n{\n    public static void TrackEvent()\n    {\n        if (DebounceMonitor.DebounceHereStatic\u003cAnalytics\u003e()) return;\n\n        // Send the event\n    }\n}\n```\n\u003csup\u003e[snippet source](/DebounceMonitoring.Tests/Snippets/Sample.cs#L52-L61)\u003c/sup\u003e\n\n### Rx Operator\n\nThis library also provides the simplest implementation of the debounce operator for [Rx.NET](https://github.com/dotnet/reactive) ([`throttle`](https://rxmarbles.com/#throttle) in RxJs).\n\n\u003cimg src=\"Assets/debounce_marble.png\" height=\"300\"\u003e\n\nExample:\n```csharp\nbutton.ClickAsObservable()\n    .Debounce()\n    .Subscribe(_ =\u003e OnButtonClick());\n```\n\u003csup\u003e[snippet source](/DebounceMonitoring.Tests/Snippets/Sample.cs#L32-L34)\u003c/sup\u003e\n\n### Interval\n\nThe default debounce interval is 500 ms.  \nIt can be specified as an argument:\n\n```csharp\nthis.DebounceHere(intervalMs: 1_000)\n\nIObservable\u003cT\u003e.Debounce(intervalMs: 1_000)\n```\nor set globally:\n\n```csharp\nDebounceMonitor.DefaultInterval = TimeSpan.FromSeconds(5);\n```\n\n### Disable (for automated testing)\n\nThe `DebounceMonitor` can be disabled in your base `TestFixture.Setup` or globally in `ModuleInitializer` with [ModuleInitializerAttribute](https://docs.microsoft.com/dotnet/api/system.runtime.compilerservices.moduleinitializerattribute) or [Fody.ModuleInit](https://github.com/Fody/ModuleInit).\n\n```csharp\ninternal static class UnitTestGlobalSetup\n{\n    [System.Runtime.CompilerServices.ModuleInitializer]\n    internal static void SetupDebounceMonitor() =\u003e DebounceMonitor.Disabled = true;\n}\n```\n\u003csup\u003e[snippet source](/DebounceMonitoring.Tests/Snippets/Sample.cs#L63-L67)\u003c/sup\u003e\n\n## How does it work?\n\nWhen `this.DebounceHere` is called, the call time is mapped to its location (method name + line number) and target (`this` in this case).\n\nOn the next call, the time is compared to the stored one. If the `interval` has not yet passed, then the call is meant to be debounced.\n\nThe debounce target (reference) is held weakly, so no memory leaks are caused.\n\n## License\n\nThis project is licensed under the MIT license - see the [LICENSE](LICENSE) file for details.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidovsky%2Fdebouncemonitoring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsidovsky%2Fdebouncemonitoring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidovsky%2Fdebouncemonitoring/lists"}