{"id":15674626,"url":"https://github.com/ctrlplusb/gun-most","last_synced_at":"2025-05-06T23:25:28.672Z","repository":{"id":57259734,"uuid":"78520056","full_name":"ctrlplusb/gun-most","owner":"ctrlplusb","description":"Extends gunDB with the ability to chain into most.js observables.","archived":false,"fork":false,"pushed_at":"2017-01-11T14:46:29.000Z","size":79,"stargazers_count":14,"open_issues_count":1,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-10T23:05:31.836Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/ctrlplusb.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":"2017-01-10T09:53:06.000Z","updated_at":"2023-01-25T17:52:22.000Z","dependencies_parsed_at":"2022-08-25T01:01:15.387Z","dependency_job_id":null,"html_url":"https://github.com/ctrlplusb/gun-most","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctrlplusb%2Fgun-most","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctrlplusb%2Fgun-most/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctrlplusb%2Fgun-most/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctrlplusb%2Fgun-most/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ctrlplusb","download_url":"https://codeload.github.com/ctrlplusb/gun-most/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252784609,"owners_count":21803718,"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":[],"created_at":"2024-10-03T15:48:29.036Z","updated_at":"2025-05-06T23:25:28.654Z","avatar_url":"https://github.com/ctrlplusb.png","language":"JavaScript","readme":"# gun-most\n\nExtends gunDB with the ability to chain into most.js observables.\n\n[![npm](https://img.shields.io/npm/v/gun-most.svg?style=flat-square)](http://npm.im/gun-most)\n[![MIT License](https://img.shields.io/npm/l/gun-most.svg?style=flat-square)](http://opensource.org/licenses/MIT)\n[![Travis](https://img.shields.io/travis/ctrlplusb/gun-most.svg?style=flat-square)](https://travis-ci.org/ctrlplusb/gun-most)\n[![Codecov](https://img.shields.io/codecov/c/github/ctrlplusb/gun-most.svg?style=flat-square)](https://codecov.io/github/ctrlplusb/gun-most)\n\n## TOCs\n\n  - [Introduction](#introduction)\n  - [Installation](#installation)\n  - [Usage](#usage)\n  - [API](#api)\n  - [Avoiding Memory Leaks](#avoiding-memory-leaks)\n\n## Introduction\n\nThis library extends the `gun` chain so that you get an `on`-equivalent observable stream that is powered by [`most`](https://github.com/cujojs/most).\n\n\u003e Note: it depends on the 0.5 beta release of gun (`npm install amark/gun#0.5`)\n\n## Installation\n\n```\nyarn add gun-most\n```\n\nOr, if you are using npm:\n\n```\nnpm install gun-most -S\n```\n\n## Usage\n\n```js\nimport 'gun-most';\nimport Gun from 'gun/gun';\n\nconst gun = Gun();\n\nconst favouriteFruit = gun.get('me').path('favouriteFruit');\n\n// Create a most stream against the item.\nconst favouriteFruit$ = favouriteFruit.most();\n\n// You now have access to all the most.js operators!\n// https://github.com/cujojs/most/blob/master/docs/api.md\n\n// Start listening to our stream.\nfavouriteFruit$.observe(x =\u003e console.log(x));\n\nfavouriteFruit.put('banana');\nfavouriteFruit.put('orange');\n```\n\nThis will result in a console output of:\n\n```\nbanana\norange\n```\n\nYou can also work against sets:\n\n```js\nimport 'gun-most';\nimport Gun from 'gun/gun';\n\nconst gun = Gun();\n\nconst fruitStock = gun.get('stock').path('fruit');\n\n// Let's create a most stream over our stock that will warn\n// us when our stock count for any fruit hits 0.\nfruitStock\n  // Use gun's map so we map over each fruit item in the set.\n  .map()\n  // Convert the result to a most stream\n  .most()\n  // Now we are in the land of most operators.\n  // https://github.com/cujojs/most/blob/master/docs/api.md\n  // Filter down to items with count being 0\n  .filter(x =\u003e x.count === 0)\n  // Print a warning!\n  .observe(({ name }) =\u003e console.log(`\"${name}\" is out of stock!`));\n\nconst banana = favouriteFruit.set({ name: 'banana', count: 100 });\nconst orange = favouriteFruit.set({ name: 'orange', count: 1337 });\n\nbanana.path('count').put(0);\n```\n\nThis will result in a console output of:\n\n```\n\"banana\" is out of stock!\n```\n\n## API\n\n### `.most([config])`\n\nThe chain operator attached to `gun` which creates a `most` Observable stream against the current `gun` context.\n\n#### Arguments\n\n  - `config` _(Object)_: The configuration object with the following properties:\n    - `[completeToken]` _(CompleteToken)_: The `CompleteToken` instance that can be used to explicitly complete the `most` stream and prevent memory leaks from occurring. See [here](#avoiding-memory-leaks) for more info.\n    - `[options]` _(Object)_: The options that should be provided to the `gun` listener. i.e. the equivalent options that are provided to the [`.on`](https://github.com/amark/gun/wiki/API-(v0.3.x)#on) operator.\n\n#### Example\n\n```js\nconst stream = gun.get('foo').most({ completeToken });\nstream.observe(data =\u003e console.log(data));\n```\n\n### `CompleteToken()`  \n\nConstructor function used to produce \"complete token\" instances to be provided to the `.most()` operator.\n\nPlease read the [\"Avoiding Memory Leaks\"](#avoiding-memory-leaks) documentation below for more information.\n\n## Avoiding Memory Leaks\n\nAfter establishing a stream against `gun` there is no way for the stream to know when to end unless all the observers attached to the stream use a \"completing\" operator such as [`take`](https://github.com/cujojs/most/blob/master/docs/api.md#take) or [`until`](https://github.com/cujojs/most/blob/master/docs/api.md#until). If the observers don't complete then the stream will continuously run, which can cause a memory leak to occur.\n\nIf you pass streams outside of the scope of your function it can be very hard to ensure that observers are using completing operators. Therefore we have created a helper called `CompleteToken` to provide you with the ability to complete/dispose streams.  It is used like so:\n\n```js\nimport { CompleteToken } from 'gun-most';\n\n// Create a complete token.\nconst completeToken = CompleteToken();\n\n// Ensure you pass it via the config object to the most operator\n//                                       👇\nconst stream = gun.get('foo').most({ completeToken });\n\n// An observer\nstream.observe(() =\u003e console.log('nothing'))\n  // Observers return promises that are resolved when the\n  // stream completes.\n  .then(() =\u003e console.log('completed'));\n\n// Running the following will complete the stream and\n// complete all observers.\ncompleteToken.complete();\n```\n\nYou have been warned and you have the tools available! 😀\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctrlplusb%2Fgun-most","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fctrlplusb%2Fgun-most","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctrlplusb%2Fgun-most/lists"}