{"id":19146691,"url":"https://github.com/koheing/observevent","last_synced_at":"2025-02-22T20:15:53.624Z","repository":{"id":45773259,"uuid":"514449356","full_name":"koheing/observevent","owner":"koheing","description":"observe event","archived":false,"fork":false,"pushed_at":"2022-09-08T13:44:33.000Z","size":1036,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-03T18:11:24.314Z","etag":null,"topics":["event","observer","observer-pattern","typescript"],"latest_commit_sha":null,"homepage":"","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/koheing.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":"2022-07-16T01:43:57.000Z","updated_at":"2022-07-20T13:30:29.000Z","dependencies_parsed_at":"2022-08-28T11:51:31.469Z","dependency_job_id":null,"html_url":"https://github.com/koheing/observevent","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koheing%2Fobservevent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koheing%2Fobservevent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koheing%2Fobservevent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koheing%2Fobservevent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koheing","download_url":"https://codeload.github.com/koheing/observevent/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240229976,"owners_count":19768597,"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":["event","observer","observer-pattern","typescript"],"created_at":"2024-11-09T07:47:43.790Z","updated_at":"2025-02-22T20:15:53.604Z","avatar_url":"https://github.com/koheing.png","language":"TypeScript","readme":"# Observevent\nEvent Observer inspired by [svelte/store](https://github.com/sveltejs/svelte) and [rxjs](https://github.com/ReactiveX/rxjs)\n\n## Installation\n```\nnpm i observevent\n```\n\n## Usage\n\n### `subjectify`\n```ts\nimport { subjectify } from 'observevent'\n\nconst food = subjectify('')\nconst unsubscribe = food.subscribe((newValue, oldValue) =\u003e console.log(newValue, oldValue))\n// or \n// food.subscribe((newValue) =\u003e console.log(newValue))\n\nfood.notify('apple')\nfood.notify((it) =\u003e it + ' pie')\n\nunsubscribe()\n\n// Output\n// ----------\n// '', undefined\n// 'apple, '\n// 'apple pie, apple'\n```\n\n### `observify`\n```ts\nimport { observify, select } from 'observevent'\nimport { EventEmitter } from 'events'\n\nconst emitter = new EventEmitter()\n\nconst logger = {\n  info: (...args: unknown[]) =\u003e console.log('[food]', ...args)\n}\n\nfunction isPie(food: string): boolean {\n  return food.indexOf('pie') \u003e -1\n}\n\nconst food = observify('', (trigger) =\u003e {\n  emitter.on('food', trigger)\n  return () =\u003e emitter.removeAllListener('food')\n}, /** Option **/  { logging: true, logger })\n\nconst unsubscribe = select(food, isPie).subscribe((it) =\u003e it)\n\nemitter.emit('food', 'apple')\n\nunsubscribe()\n\n// Output\n// ----------\n// '[food] \"\", undefined'\n// '[food] \"\", apple'\n```\n\n## Options\n`observify` and `subjectify` and `combine` and `combineMap` have the following options:\n\n### `logging`\nSetting `logging` to `true` will output changelog.  \nDefault value is `false`.  \n```ts\nimport { subjectify } from 'observevent'\n\nconst food = subjectify('', { logging: true })\nconst unsubscribe = food.subscribe((it) =\u003e it)\n\nfood.notify('apple')\nfood.notify((it) =\u003e it + ' pie')\n\nunsubscribe()\n\n// Output\n// ----------\n// { before: undefined, after: '' }\n// { before: '', after: 'apple' }\n// { before: 'apple', after: 'apple pie' }\n```\n\n### `logger`\nYou can set a custom logger.\n```ts\nimport { subjectify } from 'observevent'\n\nconst logger = {\n  info: (value: unknown) =\u003e console.log('[food]', value)\n}\n\nconst food = subjectify('', { logging: true, logger })\nconst unsubscribe = food.subscribe((it) =\u003e it)\n\nfood.notify('apple')\nfood.notify((it) =\u003e it + ' pie')\n\nunsubscribe()\n\n// Output\n// ----------\n// [food] { before: undefined, after: '' }\n// [food] { before: '', after: 'apple' }\n// [food] { before: 'apple', after: 'apple pie' }\n```\n\n### `immediate`\nIf `immediate` is set to `false`, the current value will not be notified and will be notified from changes after subscription.  \nDefault value is `true`.  \n```ts\nimport { subjectify } from 'observevent'\n\nconst food = subjectify('', { immediate: false })\nconst unsubscribe = food.subscribe((it) =\u003e console.log(it))\n\nfood.notify('apple')\nfood.notify((it) =\u003e it + ' pie')\n\nunsubscribe()\n\n// Output\n// ----------\n// 'apple'\n// 'apple pie'\n```\n\n## Derives\n- [map](https://github.com/koheing/observevent/blob/main/src/derives/map.ts)\n- [select](https://github.com/koheing/observevent/blob/main/src/derives/select.ts)\n- [exclude](https://github.com/koheing/observevent/blob/main/src/derives/exclude.ts)\n- [combine](https://github.com/koheing/observevent/blob/main/src/derives/combine.ts)\n- [combineMap](https://github.com/koheing/observevent/blob/main/src/derives/combinemap.ts)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoheing%2Fobservevent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoheing%2Fobservevent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoheing%2Fobservevent/lists"}