Avoid using small objects where possible

This commit is contained in:
Danila Fedorin 2021-08-16 16:06:22 -07:00
parent a4375c0e15
commit 410bd4ab8b
4 changed files with 9 additions and 9 deletions

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import {iterateCursor, reqAsPromise} from "./utils";
import {iterateCursor, DONE, NOT_DONE, reqAsPromise} from "./utils";
type Reducer<A,B> = (acc: B, val: A) => B
@ -101,7 +101,7 @@ export class QueryTarget<T> {
const results: T[] = [];
await iterateCursor<T>(cursor, (value) => {
results.push(value);
return {done: false};
return NOT_DONE;
});
return results;
}
@ -127,7 +127,7 @@ export class QueryTarget<T> {
let maxKey: IDBValidKey | undefined;
await iterateCursor(cursor, (_, key) => {
maxKey = key;
return {done: true};
return DONE;
});
return maxKey;
}
@ -191,7 +191,7 @@ export class QueryTarget<T> {
const cursor = this._openCursor(range, direction);
return iterateCursor<T>(cursor, (value) => {
reducedValue = reducer(reducedValue, value);
return {done: false};
return NOT_DONE;
});
}

View file

@ -14,11 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { iterateCursor, txnAsPromise } from "./utils";
import { iterateCursor, NOT_DONE, txnAsPromise } from "./utils";
import { STORE_NAMES } from "../common";
export async function exportSession(db: IDBDatabase): Promise<{ [storeName : string] : any }> {
const NOT_DONE = {done: false};
const txn = db.transaction(STORE_NAMES, "readonly");
const data = {};
await Promise.all(STORE_NAMES.map(async name => {

View file

@ -1,4 +1,4 @@
import {iterateCursor, reqAsPromise} from "./utils";
import {iterateCursor, NOT_DONE, reqAsPromise} from "./utils";
import {RoomMember, EVENT_TYPE as MEMBER_EVENT_TYPE} from "../../room/members/RoomMember.js";
import {RoomMemberStore} from "./stores/RoomMemberStore";
import {RoomStateEntry} from "./stores/RoomStateStore";
@ -21,8 +21,6 @@ export const schema = [
];
// TODO: how to deal with git merge conflicts of this array?
const NOT_DONE = {done:false};
// TypeScript note: for now, do not bother introducing interfaces / alias
// for old schemas. Just take them as `any`.

View file

@ -18,6 +18,9 @@ limitations under the License.
import { IDBRequestError } from "./error";
import { StorageError } from "../common";
export const NOT_DONE = { done: false };
export const DONE = { done: true };
let needsSyncPromise = false;
/* should be called on legacy platforms to see