66//
77
88#include " HybridMMKV.hpp"
9+ #include " MMKVListenerRegistry.hpp"
910#include " MMKVTypes.hpp"
10- #include " MMKVValueChangedListenerRegistry.hpp"
1111#include " ManagedMMBuffer.hpp"
1212#include < NitroModules/NitroLogger.hpp>
1313
@@ -64,6 +64,8 @@ HybridMMKV::HybridMMKV(const Configuration& config) : HybridObject(TAG) {
6464
6565 throw std::runtime_error (" Failed to create MMKV instance!" );
6666 }
67+
68+ MMKVListenerRegistry::registerInstance (instance);
6769}
6870
6971std::string HybridMMKV::getId () {
@@ -127,7 +129,7 @@ void HybridMMKV::set(const std::string& key, const std::variant<bool, std::share
127129 }
128130
129131 // Notify on changed
130- MMKVValueChangedListenerRegistry ::notifyOnValueChanged (instance->mmapID (), key);
132+ MMKVListenerRegistry ::notifyOnValueChanged (instance->mmapID (), key);
131133}
132134
133135std::optional<bool > HybridMMKV::getBoolean (const std::string& key) {
@@ -178,7 +180,7 @@ bool HybridMMKV::remove(const std::string& key) {
178180 bool wasRemoved = instance->removeValueForKey (key);
179181 if (wasRemoved) {
180182 // Notify on changed
181- MMKVValueChangedListenerRegistry ::notifyOnValueChanged (instance->mmapID (), key);
183+ MMKVListenerRegistry ::notifyOnValueChanged (instance->mmapID (), key);
182184 }
183185 return wasRemoved;
184186}
@@ -192,7 +194,7 @@ void HybridMMKV::clearAll() {
192194 instance->clearAll ();
193195 for (const auto & key : keysBefore) {
194196 // Notify on changed
195- MMKVValueChangedListenerRegistry ::notifyOnValueChanged (instance->mmapID (), key);
197+ MMKVListenerRegistry ::notifyOnValueChanged (instance->mmapID (), key);
196198 }
197199}
198200
@@ -224,14 +226,18 @@ void HybridMMKV::trim() {
224226 instance->clearMemoryCache ();
225227}
226228
229+ void HybridMMKV::checkExternalContentChanged () {
230+ instance->checkContentChanged ();
231+ }
232+
227233Listener HybridMMKV::addOnValueChangedListener (const std::function<void (const std::string& /* key */ )>& onValueChanged) {
228234 // Add listener
229235 auto mmkvID = instance->mmapID ();
230- auto listenerID = MMKVValueChangedListenerRegistry::addListener (mmkvID, onValueChanged);
236+ auto listenerID = MMKVListenerRegistry::addValueChangedListener (mmkvID, onValueChanged);
231237
232238 return Listener ([=]() {
233239 // remove()
234- MMKVValueChangedListenerRegistry::removeListener (mmkvID, listenerID);
240+ MMKVListenerRegistry::removeValueChangedListener (mmkvID, listenerID);
235241 });
236242}
237243
0 commit comments