Latest 1.1.2
Homepage https://github.com/LastSprint/CoreEvents
License MIT
Platforms ios 9.0
Authors

Build Status
codebeat badge

Small Swift events kit that provides some base types of events:

  • FutureEvent
  • PresentEvent
  • PastEvent

Each this type may implement some Event protocols:

  • Event it’s a object that contains any listners (swift closures) with one template parameter – emited value type.
  • EmptyEvent it’s syntactic sugar for Event with Void template parameter.
  • ValueEvent it’s event, that can contain only one listner and this listner should get and return value. This protocol contains contains two template parameters.

FutureEvent

Description

This is classic event (like C# event) that can contains many listners and multicast each new message for this listners.
This event emit only new messages. It means that if you add new listner to existed event this event doesn’t emit previous messages to new listner.

Types

  • FutureEvent: Event
  • FutureEmptyEvent: EmptyEvent
  • FutureValueEvent: ValueEvent

Example

var event = FutureEvent<Int>()

event += { value in
  print("Awesome int: (value)")
}

event.invoke(with: 42)

will print Awesome int: 42

PresentEvent

Description

This event provide all Future logic, but additionally provide emits last emited value for new listner.
It means if your event already emits value and you add new listener then yout listener handles previous emited value in the same time.

Types

  • PresentEvent: Event
  • PresentEmptyEvent: EmptyEvent

Example

var event = PresentEvent<Int>()

event += { value in
  print("Awesome int: (value)")
}

event.invoke(with: 42)

event += {
    print("Old awesome int: (value)")
}

will print:

Awesome int: 42

Old awesome int: 42

PastEvent

Description

This event like Present, but emits all previous messages for new listner

Types

  • PastEvent: Event

Example

var event = PastEvent<Int>()

event.invoke(with: 0)
event.invoke(with: 1)

event += { value in
  print("Awesome int: (value)")
}

event.invoke(with: 2)

Will print:

Awesome int: 0

Awesome int: 1

Awesome int: 2

How to install

pod 'CoreEvents', '~> 1.1.2'

Latest podspec

{
    "name": "CoreEvents",
    "version": "1.1.2",
    "summary": "Small library contains rx-like events.",
    "description": "This library contains object represents Events (like C# event). nThis may simplify things like: pub/sub, delegation, notification and other.",
    "homepage": "https://github.com/LastSprint/CoreEvents",
    "license": {
        "type": "MIT"
    },
    "authors": {
        "Alexander Kravchenkov": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/LastSprint/CoreEvents.git",
        "tag": "1.1.2"
    },
    "source_files": "CoreEvents/CoreEvents/Sources/**/*.swift",
    "pushed_with_swift_version": "4.1"
}

Pin It on Pinterest

Share This