Skip to content

Commit b1b5bcf

Browse files
authored
fix(windows): errors reported from getAllKeys/clear (#424)
`getAllKeys` was reporting the correct results, but also an empty array error. Unlike the multi* methods, these expect a single error, not an array of errors. The fix is to change the type sent by the windows implementation from an array to a single object. That object is also just a null value, since there are no errors being reported currently by the windows implementation.
1 parent 979796c commit b1b5bcf

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

windows/ReactNativeAsyncStorage/DBStorage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ void DBStorage::DBTask::getAllKeys(sqlite3* db) {
469469
auto writer = winrt::MakeJSValueTreeWriter();
470470
result.WriteTo(writer);
471471
std::vector<winrt::JSValue> callbackParams;
472-
callbackParams.push_back(winrt::JSValueArray());
472+
callbackParams.push_back(nullptr);
473473
callbackParams.push_back(winrt::TakeJSValue(writer));
474474
m_callback(callbackParams);
475475
}
@@ -478,7 +478,7 @@ void DBStorage::DBTask::getAllKeys(sqlite3* db) {
478478
void DBStorage::DBTask::clear(sqlite3* db) {
479479
if (Exec(db, m_callback, u8"DELETE FROM AsyncLocalStorage")) {
480480
std::vector<winrt::JSValue> callbackParams;
481-
callbackParams.push_back(winrt::JSValueArray());
481+
callbackParams.push_back(nullptr);
482482
m_callback(callbackParams);
483483
}
484484
}

windows/ReactNativeAsyncStorage/RNCAsyncStorage.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,28 @@ namespace winrt::ReactNativeAsyncStorage::implementation
105105
}
106106

107107
REACT_METHOD(getAllKeys);
108-
void getAllKeys(std::function<void(JSValueArray const& errors, JSValueArray const& keys)>&& callback) noexcept {
108+
void getAllKeys(std::function<void(JSValue const& error, JSValueArray const& keys)>&& callback) noexcept {
109109
dbStorage.AddTask(DBStorage::DBTask::Type::getAllKeys,
110110
[callback{ std::move(callback) }](std::vector<JSValue> const& callbackParams) {
111111
if (callbackParams.size() > 0) {
112-
auto& errors = callbackParams[0].AsArray();
112+
auto& error = callbackParams[0];
113113
if (callbackParams.size() > 1) {
114-
callback(errors, callbackParams[1].AsArray());
114+
callback(error, callbackParams[1].AsArray());
115115
}
116116
else {
117-
callback(errors, {});
117+
callback(error, {});
118118
}
119119
}
120120
});
121121
}
122122

123123
REACT_METHOD(clear);
124-
void clear(std::function<void(JSValueArray const&)>&& callback) noexcept {
124+
void clear(std::function<void(JSValue const&)>&& callback) noexcept {
125125
dbStorage.AddTask(DBStorage::DBTask::Type::clear,
126126
[callback{ std::move(callback) }](std::vector<JSValue> const& callbackParams) {
127127
if (callbackParams.size() > 0) {
128-
auto& errors = callbackParams[0].AsArray();
129-
callback(errors);
128+
auto& error = callbackParams[0];
129+
callback(error);
130130
}
131131
});
132132
}

0 commit comments

Comments
 (0)