{"id":15414892,"url":"https://github.com/lxsmnsyc/liteobservable","last_synced_at":"2025-04-19T12:47:24.978Z","repository":{"id":34078502,"uuid":"169172066","full_name":"lxsmnsyc/LiteObservable","owner":"lxsmnsyc","description":"Cold Observables for JS in a lightweight fashion","archived":false,"fork":false,"pushed_at":"2023-07-18T22:54:22.000Z","size":2023,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T02:19:35.414Z","etag":null,"topics":["observable","observable-streams","observer-pattern","reactive","reactive-programming","reactivex"],"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/lxsmnsyc.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":"2019-02-05T00:43:21.000Z","updated_at":"2023-07-15T18:13:17.000Z","dependencies_parsed_at":"2024-10-19T21:09:54.338Z","dependency_job_id":null,"html_url":"https://github.com/lxsmnsyc/LiteObservable","commit_stats":{"total_commits":67,"total_committers":2,"mean_commits":33.5,"dds":"0.23880597014925375","last_synced_commit":"38ba3981ffe6f1a2cb210f3dbe5b1c8203ada0f6"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2FLiteObservable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2FLiteObservable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2FLiteObservable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2FLiteObservable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lxsmnsyc","download_url":"https://codeload.github.com/lxsmnsyc/LiteObservable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249698416,"owners_count":21312197,"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":["observable","observable-streams","observer-pattern","reactive","reactive-programming","reactivex"],"created_at":"2024-10-01T17:05:12.138Z","updated_at":"2025-04-19T12:47:24.964Z","avatar_url":"https://github.com/lxsmnsyc.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LiteObservable\n\nCold Observables for JS in just 617 bytes.\n\n## Usage\n\n### Installing\n\nAs a node module\n\n```bash\nnpm i lite-observable\n```\n\n```yarn\nyarn add lite-observable\n```\n\n### Creating an Observable\n\n```js\nconst observable = Observable.create(emitter =\u003e {\n  emitter.next('Hello');\n  emitter.next('World');\n  emitter.complete();\n});\n```\n\nEmitters have the following properties:\n\n| Field | Type | Description |\n| --- | --- | --- |\n| next | ```function``` | Emits a value. |\n| error | ```function``` | Emits an error signal. |\n| complete | ```function``` | Emits a completion signal. |\n| subscription | ```object``` | The subscription context. |\n\n### Subscribing\n\n```js\nobservable.subscribe(\n  x =\u003e console.log(`Next: ${x}`)\n  e =\u003e console.log(`Error: ${e}`),\n  () =\u003e console.log('Completed'),\n);\n```\n\nSubscriptions have the following properties:\n\n| Field | Type | Description |\n| --- | --- | --- |\n| active | ```function``` | Returns the current state of the subscription. Returns false if the subscription is disposed or finished. |\n| dispose | ```function``` | Disposes the subscription. |\n\n### Creating your own operators\n\nWith the ```pipe``` method, it is easy to create and use your own custom operators.\n\nWhen constructing operators, it is recommended to use the constructor instead of ```create``` method to prevent subscription overhead, and to directly access the unabstracted Observer object. Use ```sub``` instead of ```subscribe``` to access the operator of the source Observable.\n\nExample below is a map and filter operators:\n\n```js\nconst map = mapper =\u003e source =\u003e new Observable((o) =\u003e {\n  const {\n    subscribe, complete, error, next,\n  } = o;\n  source.sub({\n    subscribe,\n    next: x =\u003e next(mapper(x)),\n    error,\n    complete,\n  });\n});\n\nconst filter = predicate =\u003e source =\u003e new Observable((o) =\u003e {\n  const {\n    subscribe, complete, error, next,\n  } = o;\n  source.sub({\n    subscribe,\n    next: x =\u003e predicate(x) \u0026\u0026 next(x),\n    error,\n    complete,\n  });\n});\n```\n\nExample usage:\n\n```js\nconst observable = Observable.create((e) =\u003e {\n  for (let i = 0; i \u003c 10; i += 1) {\n    e.next(i);\n  }\n  e.complete();\n});\n\nobservable.pipe(\n  filter(x =\u003e x % 2 === 0),\n  map(x =\u003e x * 2),\n  map(x =\u003e `Next: ${x}`),\n).subscribe(\n  console.log,\n);\n```\n\nwhich outputs:\n\n```\nNext: 0\nNext: 4\nNext: 8\nNext: 12\nNext: 16\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxsmnsyc%2Fliteobservable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flxsmnsyc%2Fliteobservable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxsmnsyc%2Fliteobservable/lists"}