Giter Club home page Giter Club logo

delphi-event-bus's Introduction

alt text

DEB an Event Bus framework for Delphi

Delphi Event Bus (for short DEB) is a publish/subscribe Event Bus framework for the Delphi platform.

DEB is designed to decouple different parts/layers of your application while still allowing them to communicate efficiently. It was inspired by EventBus framework for the Android platform.

alt text

Give it a star

Please "star" this project in GitHub! It costs nothing but helps to reference the code

alt text

Features

  • Easy and clean: DelphiEventBus is super easy to learn and use because it respects KISS and "Convention over configuration" design principles. By using default TEventBus instance, you can start immediately to delivery and receive events
  • Designed to decouple different parts/layers of your application
  • Event Driven
  • Attributes based API: Simply put the Subscribe attribute on your subscriber method you are able to receive a specific event
  • Support different delivery mode: Specifying the TThreadMode in Subscribe attribute, you can choose to delivery the event in the Main Thread or in a Background ones, regardless where an event was posted. The EventBus will manage Thread synchronization
  • Unit Tested
  • Thread Safe

Show me the code

Events

1.Define events:

IEvent = interface(IInterface)
['{3522E1C5-547F-4AB6-A799-5B3D3574D2FA}']
// additional information here
end;

2.Prepare subscribers:

  • Declare your subscribing method:
[Subscribe]
procedure OnEvent(AEvent: IAnyTypeOfEvent);
begin
  // manage the event 	
end;
  • Register your subscriber:
GlobalEventBus.RegisterSubscriberForEvents(Self);

3.Post events:

GlobalEventBus.post(LEvent);

Channels

1.Define channel:

const MY_CHANNEL = 'MYCHANNEL'

2.Prepare subscribers:

  • Declare your subscribing method:
[Channel(MY_CHANNEL)]
procedure OnMessage(AMsg: string);
begin
  // manage the message 	
end;
  • Register your subscriber:
GlobalEventBus.RegisterSubscriberForChannels(Self);

3.Post event on channel:

GlobalEventBus.post(MY_CHANNEL, 'My Message');

Support

  • DEB is a 100% ObjectPascal framework so it works on VCL and Firemonkey
  • It works with Delphi2010 and major

Release Notes

DEB 2.0

  • NEW! Added new Interface based mechanism to declare and handle events!
  • NEW! Added channels for simple string-based events
  • NEW! Removed internal CloneEvent because now events are interface based!

Breaking Changes

  • A subscriber method can only have 1 parameter that is an IInterface or descendants
  • EventBus.Post method can accept only an interface as parameter now

License

Copyright 2016-2020 Daniele Spinetti

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

delphi-event-bus's People

Contributors

chomps1 avatar edwinyzh avatar kevind7 avatar spinettaro avatar swiftexpat avatar viniciusfbb avatar wxinix avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.