Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EmptyDisposable #209

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions MobiusCore/Source/Disposables/EmptyDisposable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2019-2024 Spotify AB.
//
// 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.

import Foundation

/// The `EmptyDisposable` class implements a `Disposable` type for when you don't have anything to dispose of.
public final class EmptyDisposable: MobiusCore.Disposable {

/// Create an `EmptyDisposable`
public init() {}

public func dispose() {
// No-op
}
}
4 changes: 2 additions & 2 deletions MobiusCore/Source/EffectHandlers/EffectRouterDSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public extension _PartialEffectRouter {
return to { parameters, callback in
fireAndForget(parameters)
callback.end()
return AnonymousDisposable {}
return EmptyDisposable()
}
}

Expand All @@ -58,7 +58,7 @@ public extension _PartialEffectRouter {
callback.send(event)
}
callback.end()
return AnonymousDisposable {}
return EmptyDisposable()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct CompositeEventSourceBuilder<Event> {
public func build() -> AnyEventSource<Event> {
switch eventSources.count {
case 0:
return AnyEventSource { _ in AnonymousDisposable {} }
return AnyEventSource { _ in EmptyDisposable() }
case 1:
return eventSources[0]
default:
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Source/Mobius.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public enum Mobius {
return Builder(
update: update,
effectHandler: effectHandler,
eventSource: AnyEventSource({ _ in AnonymousDisposable(disposer: {}) }),
eventSource: AnyEventSource({ _ in EmptyDisposable() }),
eventConsumerTransformer: { $0 },
logger: AnyMobiusLogger(NoopLogger())
)
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/EffectHandlers/EffectHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ private func handleEffect(effect: Effect, callback: EffectCallback<Event>) -> Di
callback.send(.eventForEffect1)
}
callback.end()
return AnonymousDisposable {}
return EmptyDisposable()
}
2 changes: 1 addition & 1 deletion MobiusCore/Test/EffectHandlers/EffectRouterDSLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class EffectRouterDSLTests: QuickSpec {
expect(effect).to(equal(.effect1))
callback.send(.eventForEffect1)
callback.end()
return AnonymousDisposable {}
return EmptyDisposable()
}
.asConnectable
.connect { events.append($0) }
Expand Down
6 changes: 3 additions & 3 deletions MobiusCore/Test/EffectHandlers/EffectRouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class EffectRouterTests: QuickSpec {
.to { _, callback in
callback.send(.eventForEffect2)
callback.end()
return AnonymousDisposable {}
return EmptyDisposable()
}
.asConnectable

Expand All @@ -119,7 +119,7 @@ class EffectRouterTests: QuickSpec {

beforeEach {
let handler = AnyEffectHandler<Effect, Event> { _, _ in
AnonymousDisposable {}
EmptyDisposable()
}
let invalidRouter = EffectRouter<Effect, Event>()
.routeEffects(equalTo: .multipleHandlersForThisEffect).to(handler)
Expand Down Expand Up @@ -163,7 +163,7 @@ class EffectRouterTests: QuickSpec {
.routeEffects(equalTo: .effect2)
.to { _, callback in
callback.end()
return AnonymousDisposable {}
return EmptyDisposable()
}
.asConnectable

Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/NonReentrancyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class NonReentrancyTests: QuickSpec {

let testEffectHandler = AnyEffectHandler<Effect, Event> {
handleEffect($0, $1)
return AnonymousDisposable {}
return EmptyDisposable()
}

let effectConnectable = EffectRouter<Effect, Event>()
Expand Down
2 changes: 1 addition & 1 deletion MobiusExtras/Test/EventSource+ExtensionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EventSourceExtensionsTests: QuickSpec {
beforeEach {
intEventSource = AnyEventSource { (consumer: @escaping (Int) -> Void) in
subscribedIntConsumer = consumer
return AnonymousDisposable {}
return EmptyDisposable()
}
}

Expand Down
Loading