Skip to content

Commit

Permalink
Merge pull request #8 from surfstudio/#7_add_special_initialization
Browse files Browse the repository at this point in the history
#7 add special initialization
  • Loading branch information
LastSprint authored Aug 4, 2019
2 parents c5123c0 + 3d1cc49 commit ee5e375
Show file tree
Hide file tree
Showing 20 changed files with 359 additions and 755 deletions.
2 changes: 2 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- "CoreEvents/CoreEvents/Sources/Base"
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: Swift
osx_image: xcode9.3
osx_image: xcode10.2
xcode_project: CoreEvents/CoreEvents.xcodeproj # path to your xcodeproj folder
xcode_scheme: CoreEvents
before_install:
Expand All @@ -9,3 +9,5 @@ before_install:
script:
- set -o pipefail
- xcodebuild test -project CoreEvents/CoreEvents.xcodeproj -scheme CoreEventsTests -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO -enableCodeCoverage YES -destination 'platform=iOS Simulator,name=iPhone 8,OS=11.1' | xcpretty -c
after_success:
- bash <(curl -s https://codecov.io/bash) -t db8e8134-39fd-487b-b598-912fc126cc71
18 changes: 8 additions & 10 deletions CoreEvents.podspec
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
Pod::Spec.new do |s|

s.name = "CoreEvents"
s.version = "1.3.0"
s.summary = "Small library contains rx-like events."
s.name = "CoreEvents"
s.version = "2.0.0"
s.summary = "Small library contains rx-like events."

s.description = <<-DESC
This library contains object represents Events (like C# event).
This may simplify things like: pub/sub, delegation, notification and other.
DESC

s.homepage = "https://github.com/surfstudio/CoreEvents"
s.homepage = "https://github.com/surfstudio/CoreEvents"

s.license = { :type => "MIT" }
s.license = { :type => "MIT" }

s.author = { "Alexander Kravchenkov" => "a.a.kravchenkov@gmail.com" }
s.author = { "Alexander Kravchenkov" => "a.a.kravchenkov@gmail.com" }

s.ios.deployment_target = "9.0"

#s.osx.deployment_target = "10.10"
s.source = { :git => "https://github.com/surfstudio/CoreEvents.git", :tag => "#{s.version}" }

s.source = { :git => "https://github.com/surfstudio/CoreEvents.git", :tag => "#{s.version}" }

s.source_files = 'CoreEvents/CoreEvents/Sources/**/*.swift'
s.source_files = 'CoreEvents/CoreEvents/Sources/**/*.swift'

end
56 changes: 9 additions & 47 deletions CoreEvents/CoreEvents.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,18 @@
/* Begin PBXBuildFile section */
8B48A597208FE16F004A0266 /* CoreEvents_macOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 8B48A595208FE16F004A0266 /* CoreEvents_macOS.h */; settings = {ATTRIBUTES = (Public, ); }; };
8B48A59E208FE295004A0266 /* PresentEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A482087BE4900E1B851 /* PresentEvent.swift */; };
8B48A59F208FE298004A0266 /* PresentEmptyEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A492087BE4900E1B851 /* PresentEmptyEvent.swift */; };
8B48A5A0208FE29E004A0266 /* FutureValueEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A4B2087BE4900E1B851 /* FutureValueEvent.swift */; };
8B48A5A1208FE2A0004A0266 /* FutureEmptyEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A4C2087BE4900E1B851 /* FutureEmptyEvent.swift */; };
8B48A5A2208FE2A3004A0266 /* FutureEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A4D2087BE4900E1B851 /* FutureEvent.swift */; };
8B48A5A3208FE2A6004A0266 /* PastEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A4F2087BE4900E1B851 /* PastEvent.swift */; };
8B48A5A4208FE2AB004A0266 /* EmptyEventProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A512087BE4900E1B851 /* EmptyEventProtocol.swift */; };
8B48A5A5208FE2AD004A0266 /* EventProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A522087BE4900E1B851 /* EventProtocol.swift */; };
8B48A5A6208FE2B0004A0266 /* ValueEventProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A532087BE4900E1B851 /* ValueEventProtocol.swift */; };
8B48A5A5208FE2AD004A0266 /* Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A522087BE4900E1B851 /* Event.swift */; };
B9F71A362087BE2900E1B851 /* CoreEvents.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B9F71A2C2087BE2900E1B851 /* CoreEvents.framework */; };
B9F71A3D2087BE2900E1B851 /* CoreEvents.h in Headers */ = {isa = PBXBuildFile; fileRef = B9F71A2F2087BE2900E1B851 /* CoreEvents.h */; settings = {ATTRIBUTES = (Public, ); }; };
B9F71A542087BE4900E1B851 /* PresentEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A482087BE4900E1B851 /* PresentEvent.swift */; };
B9F71A552087BE4900E1B851 /* PresentEmptyEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A492087BE4900E1B851 /* PresentEmptyEvent.swift */; };
B9F71A562087BE4900E1B851 /* FutureValueEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A4B2087BE4900E1B851 /* FutureValueEvent.swift */; };
B9F71A572087BE4900E1B851 /* FutureEmptyEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A4C2087BE4900E1B851 /* FutureEmptyEvent.swift */; };
B9F71A582087BE4900E1B851 /* FutureEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A4D2087BE4900E1B851 /* FutureEvent.swift */; };
B9F71A592087BE4900E1B851 /* PastEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A4F2087BE4900E1B851 /* PastEvent.swift */; };
B9F71A5A2087BE4900E1B851 /* EmptyEventProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A512087BE4900E1B851 /* EmptyEventProtocol.swift */; };
B9F71A5B2087BE4900E1B851 /* EventProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A522087BE4900E1B851 /* EventProtocol.swift */; };
B9F71A5C2087BE4900E1B851 /* ValueEventProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A532087BE4900E1B851 /* ValueEventProtocol.swift */; };
B9F71A5B2087BE4900E1B851 /* Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A522087BE4900E1B851 /* Event.swift */; };
B9F71A652087BE5E00E1B851 /* PresentEventTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A5E2087BE5E00E1B851 /* PresentEventTest.swift */; };
B9F71A662087BE5E00E1B851 /* PastEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A602087BE5E00E1B851 /* PastEventTests.swift */; };
B9F71A672087BE5E00E1B851 /* FutureEventTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A622087BE5E00E1B851 /* FutureEventTest.swift */; };
B9F71A682087BE5E00E1B851 /* FutureEmptyEventTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A632087BE5E00E1B851 /* FutureEmptyEventTest.swift */; };
B9F71A692087BE5E00E1B851 /* FutureValueEventTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F71A642087BE5E00E1B851 /* FutureValueEventTest.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -55,19 +43,12 @@
B9F71A352087BE2900E1B851 /* CoreEventsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CoreEventsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
B9F71A3C2087BE2900E1B851 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B9F71A482087BE4900E1B851 /* PresentEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PresentEvent.swift; sourceTree = "<group>"; };
B9F71A492087BE4900E1B851 /* PresentEmptyEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PresentEmptyEvent.swift; sourceTree = "<group>"; };
B9F71A4B2087BE4900E1B851 /* FutureValueEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FutureValueEvent.swift; sourceTree = "<group>"; };
B9F71A4C2087BE4900E1B851 /* FutureEmptyEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FutureEmptyEvent.swift; sourceTree = "<group>"; };
B9F71A4D2087BE4900E1B851 /* FutureEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FutureEvent.swift; sourceTree = "<group>"; };
B9F71A4F2087BE4900E1B851 /* PastEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PastEvent.swift; sourceTree = "<group>"; };
B9F71A512087BE4900E1B851 /* EmptyEventProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmptyEventProtocol.swift; sourceTree = "<group>"; };
B9F71A522087BE4900E1B851 /* EventProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventProtocol.swift; sourceTree = "<group>"; };
B9F71A532087BE4900E1B851 /* ValueEventProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueEventProtocol.swift; sourceTree = "<group>"; };
B9F71A522087BE4900E1B851 /* Event.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Event.swift; sourceTree = "<group>"; };
B9F71A5E2087BE5E00E1B851 /* PresentEventTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PresentEventTest.swift; sourceTree = "<group>"; };
B9F71A602087BE5E00E1B851 /* PastEventTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PastEventTests.swift; sourceTree = "<group>"; };
B9F71A622087BE5E00E1B851 /* FutureEventTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FutureEventTest.swift; sourceTree = "<group>"; };
B9F71A632087BE5E00E1B851 /* FutureEmptyEventTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FutureEmptyEventTest.swift; sourceTree = "<group>"; };
B9F71A642087BE5E00E1B851 /* FutureValueEventTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FutureValueEventTest.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -160,7 +141,7 @@
B9F71A472087BE4900E1B851 /* PresentEvents */,
B9F71A4A2087BE4900E1B851 /* FutureEvents */,
B9F71A4E2087BE4900E1B851 /* PastEvents */,
B9F71A502087BE4900E1B851 /* Protocols */,
B9F71A502087BE4900E1B851 /* Base */,
);
path = Sources;
sourceTree = "<group>";
Expand All @@ -169,7 +150,6 @@
isa = PBXGroup;
children = (
B9F71A482087BE4900E1B851 /* PresentEvent.swift */,
B9F71A492087BE4900E1B851 /* PresentEmptyEvent.swift */,
);
path = PresentEvents;
sourceTree = "<group>";
Expand All @@ -178,8 +158,6 @@
isa = PBXGroup;
children = (
B9F71A4D2087BE4900E1B851 /* FutureEvent.swift */,
B9F71A4C2087BE4900E1B851 /* FutureEmptyEvent.swift */,
B9F71A4B2087BE4900E1B851 /* FutureValueEvent.swift */,
);
path = FutureEvents;
sourceTree = "<group>";
Expand All @@ -192,14 +170,12 @@
path = PastEvents;
sourceTree = "<group>";
};
B9F71A502087BE4900E1B851 /* Protocols */ = {
B9F71A502087BE4900E1B851 /* Base */ = {
isa = PBXGroup;
children = (
B9F71A522087BE4900E1B851 /* EventProtocol.swift */,
B9F71A512087BE4900E1B851 /* EmptyEventProtocol.swift */,
B9F71A532087BE4900E1B851 /* ValueEventProtocol.swift */,
B9F71A522087BE4900E1B851 /* Event.swift */,
);
path = Protocols;
path = Base;
sourceTree = "<group>";
};
B9F71A5D2087BE5E00E1B851 /* PresentEventTests */ = {
Expand All @@ -222,8 +198,6 @@
isa = PBXGroup;
children = (
B9F71A622087BE5E00E1B851 /* FutureEventTest.swift */,
B9F71A632087BE5E00E1B851 /* FutureEmptyEventTest.swift */,
B9F71A642087BE5E00E1B851 /* FutureValueEventTest.swift */,
);
path = FutureEventTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -375,29 +349,19 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8B48A59F208FE298004A0266 /* PresentEmptyEvent.swift in Sources */,
8B48A5A6208FE2B0004A0266 /* ValueEventProtocol.swift in Sources */,
8B48A5A1208FE2A0004A0266 /* FutureEmptyEvent.swift in Sources */,
8B48A5A5208FE2AD004A0266 /* EventProtocol.swift in Sources */,
8B48A5A0208FE29E004A0266 /* FutureValueEvent.swift in Sources */,
8B48A5A5208FE2AD004A0266 /* Event.swift in Sources */,
8B48A59E208FE295004A0266 /* PresentEvent.swift in Sources */,
8B48A5A3208FE2A6004A0266 /* PastEvent.swift in Sources */,
8B48A5A2208FE2A3004A0266 /* FutureEvent.swift in Sources */,
8B48A5A4208FE2AB004A0266 /* EmptyEventProtocol.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
B9F71A272087BE2800E1B851 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B9F71A5B2087BE4900E1B851 /* EventProtocol.swift in Sources */,
B9F71A552087BE4900E1B851 /* PresentEmptyEvent.swift in Sources */,
B9F71A572087BE4900E1B851 /* FutureEmptyEvent.swift in Sources */,
B9F71A562087BE4900E1B851 /* FutureValueEvent.swift in Sources */,
B9F71A5C2087BE4900E1B851 /* ValueEventProtocol.swift in Sources */,
B9F71A5B2087BE4900E1B851 /* Event.swift in Sources */,
B9F71A542087BE4900E1B851 /* PresentEvent.swift in Sources */,
B9F71A5A2087BE4900E1B851 /* EmptyEventProtocol.swift in Sources */,
B9F71A592087BE4900E1B851 /* PastEvent.swift in Sources */,
B9F71A582087BE4900E1B851 /* FutureEvent.swift in Sources */,
);
Expand All @@ -408,9 +372,7 @@
buildActionMask = 2147483647;
files = (
B9F71A662087BE5E00E1B851 /* PastEventTests.swift in Sources */,
B9F71A682087BE5E00E1B851 /* FutureEmptyEventTest.swift in Sources */,
B9F71A652087BE5E00E1B851 /* PresentEventTest.swift in Sources */,
B9F71A692087BE5E00E1B851 /* FutureValueEventTest.swift in Sources */,
B9F71A672087BE5E00E1B851 /* FutureEventTest.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
58 changes: 58 additions & 0 deletions CoreEvents/CoreEvents/Sources/Base/Event.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/// Абстрактный класс для события.
open class Event<Input> {

/// Тип для замыкания события.
public typealias Closure = (Input) -> Void

internal init() { }

/// Добавляет нового слушателя для события.
/// Слушатель добавляется `безопасно` - по ключу.
/// В качестве ключа по-умолчанию берется путь до файла из которого был вызыван метод.
/// - Warning: Внутри одного файла для одного события нельзя добавлять несколько слушателей без явного указания ключа.
/// В противном случае события будут перезаписаны.
/// Если вам необходимо внутри одного файла добавить больше одного слушателя - используйте собственные ключи
/// - Parameters:
/// - key: Ключ для добавления нового слушателя.
/// - listner: Слушатель.
open func add(key: String = #file, _ listner: @escaping Closure) {
fatalError("\(#function) should be overriden in child class")
}

/// Оповещает всех подписчиков данного события.
///
/// - Parameter input: Данные, которые нужно предать подписчикам.
open func invoke(with input: Input) {
fatalError("\(#function) should be overriden in child class")
}

/// Оповещает конкретного подписчика.
///
/// - Parameters:
/// - input: Данные, которые будут переданы подписчику.
/// - key: Ключ подписчика, которого нужно оповестить.
open func invoke(with input: Input, key: String = #file) {
fatalError("\(#function) should be overriden in child class")
}

/// Удаляет всех подписчиков.
open func clear() {
fatalError("\(#function) should be overriden in child class")
}

/// Удаляет конкретного подписчика.
/// Ожидается тот же ключ, что ыл добавлен в `add(by key: String = #file, _ listner: @escaping Closure)`
///
/// - Parameter key: Ключ подписчика. По-умолчанию это `#file` так же как и для `addListener`
open func remove(key: String = #file) {
fatalError("\(#function) should be overriden in child class")
}
}

public extension Event where Input == Void {

/// Синтаксический сахар. Позоляет вызвать слушателей без передачи параметра если `Input == Void`
func invoke() {
self.invoke(with: ())
}
}
35 changes: 0 additions & 35 deletions CoreEvents/CoreEvents/Sources/FutureEvents/FutureEmptyEvent.swift

This file was deleted.

38 changes: 17 additions & 21 deletions CoreEvents/CoreEvents/Sources/FutureEvents/FutureEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,37 @@
// Copyright © 2018 Alexander Kravchenkov. All rights reserved.
//

/// Future event is like Future time in English.
/// Это обыкновенное событие, которое не хранит предыдущих сообщений.
///
/// This event emits **only** new messages.
/// It's classic behaviour for event.
///
/// Provides `+=` operation for adding new listners: `event += { value in ... }`
///
/// `Input` - it's a type of value this event will emit.
/// - SeeAlso: `Event`
open class FutureEvent<Input>: Event<Input> {

public typealias Lambda = (Input) -> Void
public typealias Closure = (Input) -> Void

private var listners: [Lambda]
private var listners: [String: Closure]

public override init() {
self.listners = []
self.listners = [:]
super.init()
}

/// Add new listner.
///
/// - Parameter listner: New listner.
open override func addListner(_ listner: @escaping Lambda) {
self.listners.append(listner)

open override func add(key: String = #file, _ listner: @escaping Closure) {
self.listners[key] = listner
}

/// Notify all listners.
///
/// - Parameter input: Data for listners.
open override func invoke(with input: Input) {
self.listners.forEach({ $0(input) })
self.listners.keys.forEach { self.invoke(with: input, key: $0) }
}

open override func invoke(with input: Input, key: String = #file) {
self.listners[key]?(input)
}

/// Remove all listners.
open override func clear() {
self.listners.removeAll()
}

open override func remove(key: String = #file) {
self.listners.removeValue(forKey: key)
}
}
32 changes: 0 additions & 32 deletions CoreEvents/CoreEvents/Sources/FutureEvents/FutureValueEvent.swift

This file was deleted.

Loading

0 comments on commit ee5e375

Please sign in to comment.