{"id":21937779,"url":"https://github.com/atayahmet/observer-js","last_synced_at":"2025-07-06T17:35:18.663Z","repository":{"id":57099457,"uuid":"240955555","full_name":"atayahmet/observer-js","owner":"atayahmet","description":"Observer-js created based on observer pattern criteria. Create subjects and add it callback as observers.","archived":false,"fork":false,"pushed_at":"2020-11-17T07:36:59.000Z","size":33,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-18T10:28:08.691Z","etag":null,"topics":["callback","observer-js","pubsub","subjects"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/atayahmet.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":"2020-02-16T19:50:37.000Z","updated_at":"2023-03-04T03:34:25.000Z","dependencies_parsed_at":"2022-08-20T19:10:45.119Z","dependency_job_id":null,"html_url":"https://github.com/atayahmet/observer-js","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atayahmet%2Fobserver-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atayahmet%2Fobserver-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atayahmet%2Fobserver-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atayahmet%2Fobserver-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atayahmet","download_url":"https://codeload.github.com/atayahmet/observer-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250238986,"owners_count":21397607,"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":["callback","observer-js","pubsub","subjects"],"created_at":"2024-11-29T01:25:36.958Z","updated_at":"2025-04-22T12:26:13.818Z","avatar_url":"https://github.com/atayahmet.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cbr /\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/chakra-ui/chakra-ui/tree/master/logo\"\u003e\n    \u003cimg src=\"/logo.png\" alt=\"observer-js\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003eCreate subjects and add observers as callback. ⚡️\u003c/h1\u003e\n\n[![Travis CI](https://img.shields.io/travis/atayahmet/observer-js?style=flat-square)](https://img.shields.io/travis/atayahmet/observer-js?style=flat-square) [![Travis CI](https://img.shields.io/npm/v/@atayahmet/observer-js?style=flat-square)](https://img.shields.io/npm/v/@atayahmet/observer-js?style=flat-square) ![npm](https://img.shields.io/npm/dw/@atayahmet/observer-js?style=flat-square) ![GitHub](https://img.shields.io/github/license/atayahmet/observer-js?style=flat-square) ![GitHub issues](https://img.shields.io/github/issues/atayahmet/observer-js?style=flat-square)\n\nSimple light-weight observable pub/sub library. You can create multiple subject and observers and manage these objects using features.\n\n\u003e **Note:** All subscriptions work asynchronously.\n\n## Installation\n\nUse the package manager [yarn](https://yarnpkg.com/) or [npm](https://www.npmjs.com) to install.\n\n```sh\n$ npm i @atayahmet/observer-js --save\n```\n\n```sh\n$ yarn add @atayahmet/observer-js\n```\n\n## Usage\n\n```js\nimport Subject from '@atayahmet/observer-js';\n```\n\n**Create new subject:**\n\n```js\nconst subject = new Subject();\n\n// start subscribe\nsubject.subscribe(data =\u003e console.log('Test subscribe 1!', data));\nsubject.subscribe(data =\u003e console.log('Test subscribe 2!', data));\n\n// run all observers.\nsubject.notify('Hello World!');\n```\n\n**Unsubscribe an observer:**\n\n```js\nconst subject = new Subject();\nconst sub$ = subject.subscribe(data =\u003e console.log('Remove subscription!', data));\n\nsub$.unsubscribe();\n```\n\n**Cancel all observers in one time:**\n\n```js\nsubject.subscribe(() =\u003e console.log('Test subscribe 1!'));\nsubject.subscribe(() =\u003e console.log('Test subscribe 2!'));\n\n// cancelled.\nsubject.cancel();\n\n// this will not notify to all observers one time\nsubject.notify();\n```\n\n**Pause and Resume observers:**\n\n```js\nsubject.subscribe(() =\u003e console.log('Test subscribe 1!'));\nsubject.subscribe(() =\u003e console.log('Test subscribe 2!'));\n\n// paused all observers.\nsubject.pause();\n\n// this will not notify observers until you resume observers.\nsubject.notify();\n\n// activate all observers again.\nsubject.resume();\n```\n\n**Reset the subject completely:**\n\n```js\nsubject.reset();\n```\n\n**Get total count of active observers:**\n\n```js\nconst sub1$ = subject.subscribe(() =\u003e console.log('Test subscribe 1!'));\nconst sub2$ = subject.subscribe(() =\u003e console.log('Test subscribe 2!'));\n\nsubject.size(); // output: 2\n\nsub1$.unsubscribe();\n\nsubject.size(); // output: 1\n```\n\n**onCompleted:**\n\n```js\nsubject.subscribe(data =\u003e console.log('Test subscribe 1!'));\nsubject.subscribe(data =\u003e console.log('Test subscribe 2!'));\n\nsubject.onCompleted(() =\u003e console.log('All observers worked successfuly!'));\nsubject.notify('Go!');\n```\n\n## Built With\n\n- [TypeScript](https://www.typescriptlang.org)\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/atayahmet/observer-js/tags).\n\n## Authors\n\n- [**Ahmet ATAY**](https://github.com/atayahmet) - _Initial work_\n\nSee also the list of [contributors](https://github.com/atayahmet/observer-js/contributors) who participated in this project.\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatayahmet%2Fobserver-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatayahmet%2Fobserver-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatayahmet%2Fobserver-js/lists"}