Skip to content

Commit

Permalink
chore: rename remove to delete
Browse files Browse the repository at this point in the history
  • Loading branch information
acrazing committed Nov 13, 2024
1 parent d761bc8 commit 4e32376
Show file tree
Hide file tree
Showing 26 changed files with 63 additions and 61 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/TodoMVC/src/store/todo.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const completeTodo = action(async (dispatch, select, id: number) => {

export const deleteTodo = action(async (dispatch, select, id: number) => {
await doAsync(void 0);
dispatch([todoMapBox.removeItem(id), userTodoListBox.deleteIn(select(currentUserIdBox), id)]);
dispatch([todoMapBox.deleteItem(id), userTodoListBox.deleteIn(select(currentUserIdBox), id)]);
});

export const getTodoList = action(
Expand Down
2 changes: 1 addition & 1 deletion examples/TodoMVC/src/store/todo.boxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ signOutSignal.subscribe((dispatch, select, data) => {
return;
}
const userTodoList = select(userTodoListBox.getItem(data.userId));
dispatch([todoMapBox.removeAll(userTodoList), userTodoListBox.removeItem(data.userId)]);
dispatch([todoMapBox.deleteAll(userTodoList), userTodoListBox.deleteItem(data.userId)]);
});

export enum TodoStatusFilter {
Expand Down
2 changes: 1 addition & 1 deletion examples/TodoMVC/src/store/user.boxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const userMapBox = recordMapBox('users', UserRecord, 'id').setInitialStat

userMapBox.subscribe(signOutSignal, (state, data) => {
if (!data.keepData) {
return state.removeItem(data.userId);
return state.deleteItem(data.userId);
}
return state;
});
Expand Down
4 changes: 2 additions & 2 deletions packages/amos-boxes/src/arrayBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { Box, Mutation, ShapeBox } from 'amos-core';
import { removeElement, type ValueOrFunc } from 'amos-utils';
import { deleteElement, type ValueOrFunc } from 'amos-utils';

export interface ArrayBox<E>
extends Box<readonly E[]>,
Expand Down Expand Up @@ -35,7 +35,7 @@ export const ArrayBox = Box.extends<ArrayBox<any>>({
},
sort: (state, compare) => state.slice().sort(compare),
filter: null,
delete: (state, ...items) => removeElement(state.slice(), ...items),
delete: (state, ...items) => deleteElement(state.slice(), ...items),
},
selectors: {
at: null,
Expand Down
8 changes: 4 additions & 4 deletions packages/amos-boxes/src/mapBox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ describe('MapBox', () => {
unitMapBox.updateItem(2, (v) => (v as UserRecord).merge({ firstName: 'Morty' })),
unitMapBox.updateAll((v) => (typeof v === 'number' ? v * 2 : v)),
unitMapBox.updateAll((v) => v),
unitMapBox.removeItem(1),
unitMapBox.removeItem(3),
unitMapBox.removeAll([1, 3]),
unitMapBox.removeAll([3, 4]),
unitMapBox.deleteItem(1),
unitMapBox.deleteItem(3),
unitMapBox.deleteAll([1, 3]),
unitMapBox.deleteAll([3, 4]),
unitMapBox.clear(),
unitMapBox.reset({ 1: 2, 3: Morty }),
]).map((v) => v?.toJSON()),
Expand Down
8 changes: 4 additions & 4 deletions packages/amos-boxes/src/mapBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export interface MapBox<M extends Map<any, any> = Map<any, any>>
| 'mergeAll'
| 'updateItem'
| 'updateAll'
| 'removeItem'
| 'removeAll'
| 'deleteItem'
| 'deleteAll'
| 'clear'
| 'reset',
'getItem' | 'hasItem' | 'size',
Expand All @@ -34,8 +34,8 @@ export const MapBox = Box.extends<MapBox>({
mergeAll: null,
updateItem: null,
updateAll: null,
removeItem: null,
removeAll: null,
deleteItem: null,
deleteAll: null,
clear: null,
reset: null,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/amos-core/src/box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ export type ShapeBox<
TShape,
TMutationKeys extends keyof TShape,
TSelectorKeys extends keyof TShape,
KLimiter = TShape /* tricky for WebStorm go to definitions to shape method, if TypeScript allows P in keyof S & KM, this should be removed */,
KLimiter = TShape /* tricky for WebStorm go to definitions to shape method, if TypeScript allows P in keyof S & KM, this should be deleted */,
> = {
[P in keyof KLimiter & TMutationKeys]: TShape[P] extends (...args: infer A) => TShape
? MutationFactory<A, TShape>
Expand Down
14 changes: 7 additions & 7 deletions packages/amos-persist/src/enhancer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ describe('withPersist', () => {
const setMulti = jest.fn();
const getMulti = jest.fn();
const getPrefix = jest.fn();
const removePrefix = jest.fn();
const removeMulti = jest.fn();
const deletePrefix = jest.fn();
const deleteMulti = jest.fn();
append(engine, 'getPrefix', getPrefix);
append(engine, 'getMulti', getMulti);
append(engine, 'setMulti', setMulti);
append(engine, 'removePrefix', removePrefix);
append(engine, 'removeMulti', removeMulti);
append(engine, 'deletePrefix', deletePrefix);
append(engine, 'deleteMulti', deleteMulti);

const store = createStore(
void 0,
Expand Down Expand Up @@ -96,12 +96,12 @@ describe('withPersist', () => {
]);
expectCalledWith(getPrefix, [toKey(userMapBox)]);

store.dispatch(userMapBox.removeItem(Rick.id));
store.dispatch(userMapBox.deleteItem(Rick.id));
await sleep(1);
expectCalledWith(removeMulti, [[toKey(userMapBox, Rick.id)]]);
expectCalledWith(deleteMulti, [[toKey(userMapBox, Rick.id)]]);
store.dispatch(userMapBox.clear());
await sleep(1);
expectCalledWith(removePrefix, [toKey(userMapBox)]);
expectCalledWith(deletePrefix, [toKey(userMapBox)]);
await store.dispatch(hydrate([sessionMapBox]));
expectCalledWith(getPrefix, [toKey(sessionMapBox)]);
store.select(postMapBox.getItem(1));
Expand Down
12 changes: 6 additions & 6 deletions packages/amos-persist/src/persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const createPersist = (store: Store, finalOptions: PersistOptions) => {

const snapshot = store.snapshot();
const entries: PersistEntry[] = [];
const removes: string[] = [];
const removePrefixes: string[] = [];
const deletes: string[] = [];
const deletePrefixes: string[] = [];
for (const k in snapshot) {
const box = Box.get(k);
if (!shouldPersist(state, box)) {
Expand All @@ -34,7 +34,7 @@ export const createPersist = (store: Store, finalOptions: PersistOptions) => {
const prevRows = box.table.toRows(prev);
const keys = Object.keys(currRows);
if (keys.length === 0) {
removePrefixes.push(toKey(box));
deletePrefixes.push(toKey(box));
} else {
for (const k of keys) {
if (prevRows[k] !== currRows[k]) {
Expand All @@ -43,7 +43,7 @@ export const createPersist = (store: Store, finalOptions: PersistOptions) => {
}
for (const k in prevRows) {
if (!Object.hasOwn(currRows, k)) {
removes.push(toKey(box, k));
deletes.push(toKey(box, k));
}
}
}
Expand All @@ -53,8 +53,8 @@ export const createPersist = (store: Store, finalOptions: PersistOptions) => {
}
await Promise.all([
entries.length ? state.storage.setMulti(entries) : void 0,
removes.length ? state.storage.removeMulti(removes) : void 0,
...removePrefixes.map((p) => state.storage.removePrefix(p)),
deletes.length ? state.storage.deleteMulti(deletes) : void 0,
...deletePrefixes.map((p) => state.storage.deletePrefix(p)),
]);
}, finalOptions.onError);
};
4 changes: 2 additions & 2 deletions packages/amos-persist/src/storages/IDBStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class IDBStorage implements StorageEngine {
});
}

removeMulti(items: readonly string[]): Promise<void> {
deleteMulti(items: readonly string[]): Promise<void> {
return new Promise<void>((resolve, reject) => {
let transaction = this.db.transaction([this.table], 'readwrite');
transaction.oncomplete = () => resolve();
Expand All @@ -94,7 +94,7 @@ export class IDBStorage implements StorageEngine {
});
}

removePrefix(prefix: string): Promise<void> {
deletePrefix(prefix: string): Promise<void> {
return new Promise<void>((resolve, reject) => {
let transaction = this.db.transaction([this.table], 'readwrite');
transaction.oncomplete = () => resolve();
Expand Down
4 changes: 2 additions & 2 deletions packages/amos-persist/src/storages/MemoryStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export class MemoryStorage implements StorageEngine {
items.forEach(([k, v, d]) => (this.data[k] = [v, d]));
}

async removeMulti(items: readonly string[]): Promise<void> {
async deleteMulti(items: readonly string[]): Promise<void> {
items.forEach((k) => {
delete this.data[k];
});
}

async removePrefix(prefix: string): Promise<void> {
async deletePrefix(prefix: string): Promise<void> {
for (const k in this.data) {
if (k.startsWith(prefix)) {
delete this.data[k];
Expand Down
4 changes: 2 additions & 2 deletions packages/amos-persist/src/storages/SQLiteStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class SQLiteStorage implements StorageEngine {
);
}

async removeMulti(items: readonly string[]): Promise<void> {
async deleteMulti(items: readonly string[]): Promise<void> {
const rows = items.map(() => '?').join(', ');
await this.db.runAsync(
`DELETE
Expand All @@ -85,7 +85,7 @@ export class SQLiteStorage implements StorageEngine {
);
}

async removePrefix(prefix: string): Promise<void> {
async deletePrefix(prefix: string): Promise<void> {
await this.db.runAsync(
`DELETE
FROM ${this.table}
Expand Down
4 changes: 2 additions & 2 deletions packages/amos-persist/src/storages/SimpleStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export class SimpleStorage implements StorageEngine {
}
}

async removeMulti(items: readonly string[]): Promise<void> {
async deleteMulti(items: readonly string[]): Promise<void> {
await Promise.all(items.map((key) => this.driver.removeItem(this.genKey(key))));
}

async removePrefix(prefix: string): Promise<void> {
async deletePrefix(prefix: string): Promise<void> {
const keys = await this.allKeys(prefix);
await Promise.all(keys.map((k) => this.driver.removeItem(this.genKey(k))));
}
Expand Down
4 changes: 2 additions & 2 deletions packages/amos-persist/src/storages/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export interface StorageEngine {
getMulti(items: readonly string[]): Promise<readonly (PersistValue | null)[]>;
getPrefix(prefix: string): Promise<readonly PersistEntry[]>;
setMulti(items: readonly PersistEntry[]): Promise<void>;
removeMulti(items: readonly string[]): Promise<void>;
removePrefix(prefix: string): Promise<void>;
deleteMulti(items: readonly string[]): Promise<void>;
deletePrefix(prefix: string): Promise<void>;
}
2 changes: 1 addition & 1 deletion packages/amos-persist/src/storages/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function testStorage(s: StorageEngine) {
]),
]),
).toEqual([void 0, void 0]);
expect(await Promise.all([s.removeMulti(['A:2', 'B:3']), s.removePrefix('C:')])).toEqual([
expect(await Promise.all([s.deleteMulti(['A:2', 'B:3']), s.deletePrefix('C:')])).toEqual([
void 0,
void 0,
]);
Expand Down
12 changes: 6 additions & 6 deletions packages/amos-shapes/src/Map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ describe('Map', () => {
m1.mergeAll([[3, -1]]),
m1.updateItem(3, takeFirst),
m1.updateAll(takeFirst),
m1.removeItem(4),
m1.removeAll([4, 5]),
m1.deleteItem(4),
m1.deleteAll([4, 5]),
]).toEqual([m1, m1, m1, m1, m1, m1, m1, m1, m1, m1, m1]);
});
it('should update map', () => {
Expand Down Expand Up @@ -60,10 +60,10 @@ describe('Map', () => {
m1.updateItem(3, (v) => v - 1),
m1.updateItem(4, (v) => v + 2),
m1.updateAll((v) => v * 2),
m1.removeItem(3),
m1.removeItem(4),
m1.removeAll([3, 4]),
m1.removeAll([3, 2].values()),
m1.deleteItem(3),
m1.deleteItem(4),
m1.deleteAll([3, 4]),
m1.deleteAll([3, 2].values()),
m1.clear(),
].map((v) => (v instanceof Map ? v.toJSON() : void 0)),
).toEqual([
Expand Down
6 changes: 3 additions & 3 deletions packages/amos-shapes/src/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ export class Map<K extends ID, V> implements JSONSerializable<Record<K, V>> {
return this;
}

removeItem(key: K): this {
return this.removeAll([key]);
deleteItem(key: K): this {
return this.deleteAll([key]);
}

removeAll(keys: Iterable<K> | readonly K[]) {
deleteAll(keys: Iterable<K> | readonly K[]) {
const keysArr = toArray(keys).filter((k) => this.hasItem(k));
if (!keysArr.length) {
return this;
Expand Down
6 changes: 3 additions & 3 deletions packages/amos-testing/src/HttpEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author junbao <[email protected]>
*/

import { PartialRequired, removeElement } from 'amos-utils';
import { PartialRequired, deleteElement } from 'amos-utils';
import { MediaModel, PostModel } from './store/post.boxes';

export interface HttpEndpoints {
Expand Down Expand Up @@ -86,12 +86,12 @@ export const mockServer: {
return {};
},
'DELETE/postMedias.deletePostMedia': (req) => {
removeElement(postMedias[medias[req.id].id], req.id);
deleteElement(postMedias[medias[req.id].id], req.id);
delete medias[req.id];
return {};
},
'DELETE/posts.deletePost': (req) => {
removeElement(userPosts[posts[req.id].authorId], req.id);
deleteElement(userPosts[posts[req.id].authorId], req.id);
delete posts[req.id];
return {};
},
Expand Down
8 changes: 4 additions & 4 deletions packages/amos-testing/src/store/post.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export const updatePost = createHttpAction({
mutations: (select, result, args) => postMapBox.mergeItem(args),
});

export const removePost = createHttpAction({
export const deletePost = createHttpAction({
key: 'DELETE/posts.deletePost',
optimistic: true,
mutations: (select, result, args) => [
postMapBox.removeItem(args.id),
postMapBox.deleteItem(args.id),
userPostListBox.deleteIn(select(selectUserId()), args.id),
],
});
Expand Down Expand Up @@ -63,11 +63,11 @@ export const addPostMedia = createHttpAction({
mutations: (select, r) => [postMediaListBox.pushIn(r.postId, r.id), mediaMapBox.mergeItem(r)],
});

export const removePostMedia = createHttpAction({
export const deletePostMedia = createHttpAction({
key: 'DELETE/postMedias.deletePostMedia',
optimistic: true,
mutations: (select, result, args) => [
postMediaListBox.deleteIn(select(mediaMapBox.getItem(args.id)).postId, args.id),
mediaMapBox.removeItem(args.id),
mediaMapBox.deleteItem(args.id),
],
});
2 changes: 1 addition & 1 deletion packages/amos-testing/src/store/session.boxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export class SessionRecord extends Record<SessionModel>({
}

export const sessionMapBox = recordMapBox('sessions', SessionRecord, 'id');
sessionMapBox.subscribe(LOGOUT, (state, data) => state.removeItem(data.sessionId));
sessionMapBox.subscribe(LOGOUT, (state, data) => state.deleteItem(data.sessionId));

export const sessionIdBox = box('sessions.currentId', 0);
4 changes: 2 additions & 2 deletions packages/amos-utils/src/enhancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author junbao <[email protected]>
*/

import { must, removeElement } from './misc';
import { must, deleteElement } from './misc';
import { FuncParams, Unsubscribe } from './types';

export type Enhancer<A extends any[], V> = (next: (...args: A) => V) => (...args: A) => V;
Expand All @@ -30,7 +30,7 @@ export function enhancerCollector<A extends any[], V>(): EnhancerCollector<A, V>
must(!enhancers.includes(e), 'enhancer is already exists');
enhancers.push(e);
return () => {
removeElement(enhancers, e);
deleteElement(enhancers, e);
};
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/amos-utils/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ToJSON<T> {

export interface FromJS<T> {
// should satisfy the expression: state === toJS(fromJS(state))
// which means: should fully remove current state, and merge deeply.
// which means: should fully delete current state, and merge deeply.
fromJS(state: JSONState<T>): this;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/amos-utils/src/misc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
must,
nextSerialTicker,
NotImplemented,
removeElement,
deleteElement,
resolveConstructorValue,
resolveFuncValue,
toArray,
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('misc utils', () => {
expect(resolveFuncValue((v: number) => v * 2, 3)).toEqual(6);

const arr = [1, 3, 2, 3, 1];
expect(removeElement(arr, 3) === arr).toBe(true);
expect(deleteElement(arr, 3) === arr).toBe(true);
expect(arr).toEqual([1, 2, 3, 1]);

expect(toArray(1)).toEqual([1]);
Expand Down
Loading

0 comments on commit 4e32376

Please sign in to comment.