Skip to content

Commit

Permalink
feat: move in memory store to core package
Browse files Browse the repository at this point in the history
  • Loading branch information
luisburgos committed Sep 8, 2022
1 parent d07d31a commit f5115a1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:buzz_ui/in_memory_events_store.dart';
import 'package:core/core.dart';

import '../model/profile.dart';
import '../model/profile_user_info.dart';
Expand Down
25 changes: 1 addition & 24 deletions example/packages/buzz_ui/lib/in_memory_events_store.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:rxdart/rxdart.dart';
import 'package:core/core.dart';

abstract class EventRecord {
String get name;
Expand Down Expand Up @@ -32,26 +32,3 @@ class EventRecordsInMemoryStore {
_state.value.add(event);
}
}

/// An in-memory store backed by BehaviorSubject that can be used to
/// store the data for all the fake repositories in the app.
class InMemoryStore<T> {
InMemoryStore(T initial) : _subject = BehaviorSubject<T>.seeded(initial);

/// The BehaviorSubject that holds the data
final BehaviorSubject<T> _subject;

bool get isWaiting => !_subject.hasValue && !_subject.hasError;

/// The output stream that can be used to listen to the data
Stream<T> get stream => _subject.stream;

/// A synchronous getter for the current value
T get value => _subject.value;

/// A setter for updating the value
set value(T value) => _subject.add(value);

/// Don't forget to call this when done
void close() => _subject.close();
}
7 changes: 4 additions & 3 deletions example/packages/core/lib/core.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library core;

export 'json_reader.dart';
export 'managed_stream_builder.dart';
export 'named_page.dart';
export 'src/in_memory_store.dart';
export 'src/json_reader.dart';
export 'src/managed_stream_builder.dart';
export 'src/named_page.dart';
24 changes: 24 additions & 0 deletions example/packages/core/lib/src/in_memory_store.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:rxdart/rxdart.dart';

/// An in-memory store backed by BehaviorSubject that can be used to
/// store the data for all the fake repositories in the app.
class InMemoryStore<T> {
InMemoryStore(T initial) : _subject = BehaviorSubject<T>.seeded(initial);

/// The BehaviorSubject that holds the data
final BehaviorSubject<T> _subject;

bool get isWaiting => !_subject.hasValue && !_subject.hasError;

/// The output stream that can be used to listen to the data
Stream<T> get stream => _subject.stream;

/// A synchronous getter for the current value
T get value => _subject.value;

/// A setter for updating the value
set value(T value) => _subject.add(value);

/// Don't forget to call this when done
void close() => _subject.close();
}
File renamed without changes.
File renamed without changes.

0 comments on commit f5115a1

Please sign in to comment.