{"id":16720912,"url":"https://github.com/yoavniran/node-venter","last_synced_at":"2025-03-15T12:22:47.920Z","repository":{"id":22252476,"uuid":"25586096","full_name":"yoavniran/node-venter","owner":"yoavniran","description":"simple pub/sub class with support for scopes and namespaces","archived":false,"fork":false,"pushed_at":"2015-02-03T09:23:15.000Z","size":152,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-27T05:19:50.622Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/yoavniran.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":"2014-10-22T14:32:51.000Z","updated_at":"2015-02-03T09:23:15.000Z","dependencies_parsed_at":"2022-08-21T00:30:59.223Z","dependency_job_id":null,"html_url":"https://github.com/yoavniran/node-venter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoavniran%2Fnode-venter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoavniran%2Fnode-venter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoavniran%2Fnode-venter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoavniran%2Fnode-venter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoavniran","download_url":"https://codeload.github.com/yoavniran/node-venter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243727000,"owners_count":20337925,"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-12T22:27:27.871Z","updated_at":"2025-03-15T12:22:47.893Z","avatar_url":"https://github.com/yoavniran.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"node-venter\n=========\n\nA simple pub/sub class with support for scopes and namespaces.\n\nVenter extends Node's [EventEmitter] class.\n\n**Scopes**\n\nScopes mean you can create different instances of Venter so they have seperate pub/sub channels and life-cycle\n\n**Namespaces**\n\nNamespaces mean you can subscribe to the same event multiple times from the same method with the same handler(callback). Additionally, namespaces allow you to unregister from one event while leaving other handlers in place.\n\nThese come in handy when you have an event you'd like to listen to with one callback and the code registering the handler is part of more than one flow. the different flows may happen or not within the lifetime of your application. Without namespaces it will be difficult implementing this and have the listeners registered and unregistered appropriately.\n\nAPI\n----\n\n### Venter\n\n* **getScope()** \n\n    Return the scope the venter was initialized with.\n\n\n* **addListener(type, listener, [namespace])**\n\u003e Alias: on\n\n    Adds a listener to the end of the listeners array for the specified event.\n\n* **emit(type, [p1,p2,...]**\n\u003e Alias: trigger\n\n    Execute each of the listeners in order with the supplied arguments.\n    if a namespace is registered for the provided type, listeners that were registered with or without a namespace will be executed.\n     \n* **removeListener(type, listener, [namespace])**\n\u003e Alias: off\n\n    Remove a listener from the listener array for the specified event. Caution: changes array indices in the listener array behind the listener.\n    if a namespace is provided, only the listener that was registered with the same namespace will be removed.\n\n\n* **removeAllListeners(type, [namespace])**\n\n    Removes all listeners, or those of the specified event. It's not a good idea to remove listeners that were added elsewhere in the code, especially when it's on an emitter that you didn't create (e.g. sockets or file streams).\n    if a namespace is provided, only the listeners that were registered with the same namespace will be removed.\n     \n* **hasListener(type, [namespace])**\n\n    Returns true if a listener was registered for the provided type.\n    if a namespace is provided, will only return true if a listener was registered with that namespace.\n\n* ##### for the rest of the API, see the node documentation ([EventEmitter]) \n\n\n \n### Registrar\n\n* **get(scope)**\n\n    creates a new venter instance in the provided scope or returns an existing one if one already created.\n\n* **remove(scope)**\n\n    removes a venter (and its listeners) for the provided scope.\n\n\nExamples\n----\n\n\n**Example #1 - Simple**\n\n```javascript\nvar Venter = require(\"venter\");\n\nvar testVenter = Venter.get(\"my-test-scope\");\n\ntestVenter.on(\"some_event\", function(){console.log(\"hello\");}); //on=addListener\n\ntestVenter.emit(\"some_event\"); \n\n//prints 'hello' to console\n```\n\n**Example #2 - With Namespace**\n\n```javascript\nvar fileVenter = require(\"venter\").get(\"files\");\n\nfunction updateFile(file){\n\n  //update the file\n  \n  fileVenter.trigger(\"file_event\", file); //trigger=emit\n}\n\nfunction onFileUpdate(viewName, fileData){\n    console.log(\"something happened with the file: \", fileData);\n    \n    //update the relevant view\n}\n\nfunction getFilesFromDir(viewName, dir_name, filter){\n    \n    if (!fileVenter.hasListener(\"file_event\", fileName)){\n        //registers to 'file_event' with the filter as the namespace \n        fileVenter.addListener(\"file_event\", onFileUpdate.bind(null, viewName), filter); \n    }\n    \n    //return files from dir based on filter\n}\n\ngetFilesFromDir(\"main-view\", \"dir1\", \"*.jpg\"); //called from view a\ngetFilesFromDir(\"list-view\", \"dir1\", \"*.gif\"); //called from view b\n\nupdateFile(\"dir1/vaction.jpg\");\nupdateFile(\"dir1/dancing_kitty.gif\");\n```\n\n[EventEmitter]:http://nodejs.org/api/events.html#events_class_events_eventemitter\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoavniran%2Fnode-venter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoavniran%2Fnode-venter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoavniran%2Fnode-venter/lists"}