{"id":13429620,"url":"https://github.com/krisleech/evented","last_synced_at":"2025-06-12T21:03:57.143Z","repository":{"id":35642636,"uuid":"39917052","full_name":"krisleech/evented","owner":"krisleech","description":"Publish and Subscribe for Crystal objects","archived":false,"fork":false,"pushed_at":"2018-01-26T11:02:25.000Z","size":9,"stargazers_count":34,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-13T03:06:52.652Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Crystal","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/krisleech.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":"2015-07-29T21:23:08.000Z","updated_at":"2022-07-18T20:29:36.000Z","dependencies_parsed_at":"2022-09-18T06:55:45.541Z","dependency_job_id":null,"html_url":"https://github.com/krisleech/evented","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/krisleech%2Fevented","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2Fevented/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2Fevented/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2Fevented/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krisleech","download_url":"https://codeload.github.com/krisleech/evented/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249299678,"owners_count":21246876,"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-07-31T02:00:42.581Z","updated_at":"2025-04-17T01:52:50.672Z","avatar_url":"https://github.com/krisleech.png","language":"Crystal","funding_links":[],"categories":["Misc"],"sub_categories":[],"readme":"# Evented\n\n*A micro library providing Crystal objects with Publish-Subscribe capabilities*\n\n[![Build Status](https://travis-ci.org/krisleech/evented.png?branch=master)](https://travis-ci.org/krisleech/evented)\n\n* Decouple core business logic from external concerns in Hexagonal style architectures\n* Use as an alternative to callbacks and Observers\n* Connect objects based on context without permanence\n* React to events synchronously\n\n## Installation\n\nAdd this to your application's `shard.yml`:\n\n```yaml\ndependencies:\n  evented:\n    github: krisleech/evented\n```\n\n## Usage\n\n### Publishing\n\nBy including `Evented::Publisher` your objects get `broadcast` and\n`subscribe` methods.\n\n`broadcast` can be called from within your object whenever you want to\nbroadcast a significant event.\n\n```crystal\nrequire \"evented\"\n\nclass MyPublisher\n  include Evented::Publisher\n\n  def call(input)\n    result = do_something(input)\n    broadcast(:something_happened, result)\n  end\nend\n```\n\n### Subscribing\n\nTo subscribe an object to receive events include `Evented::Subscriber` and\nprovide your own `on_event` method which will receive 2 arguments, the\n`event_name` and `payload`.\n\n```crystal\nrequire \"evented\"\n\nclass MySubscriber\n  include Evented::Subscriber\n\n  def on_event(event_name, payload)\n    # ...\n  end\nend\n```\n\nTo subscribe the listener to a publisher:\n\n```crystal\npublisher = MyPublisher.new\npublisher.subscribe(MySubscriber.new)\n\npublisher.call(\"hello\")\n```\n\nIn the above example the subscriber will have `on_event(:something_happened, \"hello\")`\ncalled.\n\n## Development\n\n### Specs\n\n```\ncrystal spec\n```\n\n### Automatically run Specs\n\n```\nls ./**/*.cr | entr crystal spec\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/krisleech/evented/fork )\n2. Create your feature branch (git checkout -b my-new-feature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Push to the branch (git push origin my-new-feature)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Kris Leech](https://github.com/krisleech) - creator, maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrisleech%2Fevented","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrisleech%2Fevented","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrisleech%2Fevented/lists"}