-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added missing interfaces and implementations for backing stores
- Loading branch information
1 parent
bd3c576
commit 8749570
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
part of '../../kiota_abstractions.dart'; | ||
|
||
/// This class is used to register the backing store factory. | ||
class BackingStoreFactorySingleton { | ||
static final BackingStoreFactory _instance = InMemoryBackingStoreFactory(); | ||
|
||
/// The backing store factory singleton instance. | ||
static BackingStoreFactory get instance => _instance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
part of '../../kiota_abstractions.dart'; | ||
|
||
/// Proxy implementation of [ParseNodeFactory] that allows for the | ||
/// [BackingStore] that automatically sets the state of the [BackingStore] | ||
/// when deserializing. | ||
class BackingStoreParseNodeFactory extends ParseNodeProxyFactory { | ||
/// Creates a new instance of the [BackingStoreParseNodeFactory] class. | ||
BackingStoreParseNodeFactory({ | ||
required super.concrete, | ||
}) : super( | ||
onBefore: (parsable) { | ||
if (parsable is BackedModel) { | ||
final model = parsable as BackedModel; | ||
if (model.backingStore != null) { | ||
model.backingStore!.initializationCompleted = false; | ||
} | ||
} | ||
}, | ||
onAfter: (parsable) { | ||
if (parsable is BackedModel) { | ||
final model = parsable as BackedModel; | ||
if (model.backingStore != null) { | ||
model.backingStore!.initializationCompleted = true; | ||
} | ||
} | ||
}, | ||
); | ||
} |
42 changes: 42 additions & 0 deletions
42
lib/src/store/backing_store_serialization_writer_proxy_factory.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
part of '../../kiota_abstractions.dart'; | ||
|
||
/// Proxy implementation of [SerializationWriterFactory] for the [BackingStore] | ||
/// that automatically sets the state of the backing store when serializing. | ||
class BackingStoreSerializationWriterProxyFactory | ||
extends SerializationWriterProxyFactory { | ||
/// Creates a new instance of [BackingStoreSerializationWriterProxyFactory] | ||
/// with the provided concrete factory. | ||
BackingStoreSerializationWriterProxyFactory({ | ||
required super.concrete, | ||
}) : super( | ||
onBefore: (p) { | ||
if (p is BackedModel) { | ||
final model = p as BackedModel; | ||
if (model.backingStore != null) { | ||
model.backingStore!.returnOnlyChangedValues = true; | ||
} | ||
} | ||
}, | ||
onAfter: (p) { | ||
if (p is BackedModel) { | ||
final model = p as BackedModel; | ||
if (model.backingStore != null) { | ||
model.backingStore!.returnOnlyChangedValues = false; | ||
model.backingStore!.initializationCompleted = true; | ||
} | ||
} | ||
}, | ||
onStart: (p, writer) { | ||
if (p is BackedModel) { | ||
final model = p as BackedModel; | ||
if (model.backingStore != null) { | ||
model.backingStore! | ||
.iterateKeysForValuesChangedToNull() | ||
.forEach((element) { | ||
writer.writeNullValue(element); | ||
}); | ||
} | ||
} | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
part of '../../kiota_abstractions.dart'; | ||
|
||
/// This class is used to create instances of [InMemoryBackingStore]. | ||
class InMemoryBackingStoreFactory implements BackingStoreFactory { | ||
@override | ||
BackingStore createBackingStore() => InMemoryBackingStore(); | ||
} |