{"id":23080888,"url":"https://github.com/antimonit/eventsubject","last_synced_at":"2025-08-15T22:31:32.243Z","repository":{"id":57732429,"uuid":"165399289","full_name":"Antimonit/EventSubject","owner":"Antimonit","description":"Event Subject for RxJava.","archived":false,"fork":false,"pushed_at":"2021-07-11T06:34:26.000Z","size":114,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-05-25T14:16:35.281Z","etag":null,"topics":["rxjava3","subject"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Antimonit.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}},"created_at":"2019-01-12T14:51:14.000Z","updated_at":"2021-07-11T06:47:32.000Z","dependencies_parsed_at":"2022-09-10T19:52:14.925Z","dependency_job_id":null,"html_url":"https://github.com/Antimonit/EventSubject","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antimonit%2FEventSubject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antimonit%2FEventSubject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antimonit%2FEventSubject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antimonit%2FEventSubject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Antimonit","download_url":"https://codeload.github.com/Antimonit/EventSubject/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229964391,"owners_count":18152034,"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":["rxjava3","subject"],"created_at":"2024-12-16T13:17:04.021Z","updated_at":"2024-12-16T13:17:04.685Z","avatar_url":"https://github.com/Antimonit.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[ ![Download](https://maven-badges.herokuapp.com/maven-central/io.github.antimonit/eventsubject/badge.svg) ](https://search.maven.org/artifact/io.github.antimonit/eventsubject/1.1.0/jar)\n\n# EventSubject\n\n`BehaviorSubject` is often used to hold the most recent **state** as it always provides the latest \nvalue it receives.\n\nThis is often utilized with MVVM architecture in Android where ViewModel define its **state** as \na `BehaviorSubject` to which View subscribes to observe the latest changes in **state**. This is \ndone mainly because ViewModel's lifecycle is longer than that of View and we need to be able to \nunsubscribe and resubscribe whenever there is a configuration change.\n\nBut not only the **state** needs to be communicated to View. Often times there are situations where \nwe need to send a signal to View, such as a command to open a confirmation dialog. We can call such \nsignals **events**. There are notable differences between the two:\n*  A **state** has a timespan — it is valid for a period of time. Usually we are interested only in \nthe latest **state**.\n*  An **event** does not have a timespan — it occurs and immediately is over. Usually we are \ninterested in all **events**.\n\n`BehaviorSubject` is a great fit for **states** but not so much for **events** because it emits\na value *at least once*. We don't want to process an **event** again when we resubscribe to the \nsubject.\n\n`PublishSubject` is more suitable for **events** in a sense that it does not emit any values upon \nresubscription. But it emits the value *at most once*. An **event** is lost if it occurs when there \nis no subscriber.\n\n`EventSubject` is specifically designed to emit each value *exactly once*. Whenever no Observer is \nobserving, **events** are being queued up. That ensures no **events** are lost. Whenever a new \nObserver subscribes, all queued up **events** are replayed and removed from the queue. That ensures \nno **event** is processed twice. While an Observer is subscribed all **events** are relayed to the \nObserver directly.\n\n## Implementation\n\nInternally, `EventSubject` is similar to\n\u003ca href=\"http://reactivex.io/RxJava/javadoc/io/reactivex/subjects/UnicastSubject.html\"\u003eUnicastSubject\u003c/a\u003e.\nJust like `UnicastSubject`, events are queued up whenever no Observer is subscribed. Whenever a new \nObserver subscribes to this, the queued up events are replayed and the queue subsequently emptied. \nWhile an Observer is subscribed all emission are relayed to the Observer directly.\n\n`UnicastSubject` allows only a single Subscriber during its lifespan. `EventSubject` relaxes this \nin a sense that it allows only one Observer to be subscribed at a time but when it unsubscribes, \nanother one is allowed to resubscribe to this subject again.\n\n\u003cimg width=\"640\" height=\"370\" src=\"EventSubject.png\" alt=\"\"\u003e\n\nIf an Observer attempts to subscribe to an `EventSubject` that already has another Observer \nsubscribed already, the Observer attempting to subscribe will receive an `IllegalStateException`.\n\nAll other properties of this `EventSubject` are the same as of `UnicastSubject`.\n\n## Dependency\nLibrary can be added as a dependency from `mavenCentral` repository:\n```\ndependencies {\n    implementation 'io.github.antimonit:eventsubject:1.1.0'\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantimonit%2Feventsubject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantimonit%2Feventsubject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantimonit%2Feventsubject/lists"}