https://github.com/zunjae/kount
Count and react
https://github.com/zunjae/kount
Last synced: 8 months ago
JSON representation
Count and react
- Host: GitHub
- URL: https://github.com/zunjae/kount
- Owner: zunjae
- Created: 2019-06-27T14:34:49.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-17T07:32:25.000Z (over 6 years ago)
- Last Synced: 2025-09-09T12:37:00.783Z (9 months ago)
- Language: Kotlin
- Size: 11.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Kount
Perform actions based on a counter
## Why
I created this library because I didn't really like [Once](https://github.com/jonfinerty/Once)
## Setup
* Include Kount.kt in your project.
## Usage
* Create an instance of Kount
* If you use Koin, then register as follows:
```Kotlin
val koinModule: Module = module {
single { Kount(WhateverSharedPreference()) as Kountable }
}
```
and lazily inject like:
```Kotlin
val counters: Kountable by inject()
```
Now check what available method you need. Here is a sample usage:
```Kotlin
val key = "PageVisits"
val currentCounter = counters.count(key) // returns null because this key doesn't exist
counters.matches(key, Komparison.Exactly(5)) // returns false AND sets the value of `key` to 1
counters.matches(key, Komparison.LessThan(5)) // returns true AND sets the value of `key` to 2
counters.matches(key, Komparison.Repeat(2, 2) // returns true AND sets the value of `key` to 3
```
The `Repeat` option is my favorite one. You can repeat a task for Y amount of times every X time you call `matches` on it!
Look at the code to see how it works.
## Contributing
Pull requests are not welcome
## TODO:
* Add a value change listener
## License
This project is available under the MIT license, though there is no need to include a license and copyright notice