refactor: convert function expressions to declarations (#4926)
This commit is contained in:
committed by
GitHub
parent
c0236536dd
commit
141a2eba56
@ -27,7 +27,7 @@ export type CursorStore = {
|
||||
|
||||
type ActionHandler = (action: string) => unknown;
|
||||
|
||||
const jsToMap = (obj: {}) => {
|
||||
function jsToMap(obj: {}) {
|
||||
if (obj === undefined) {
|
||||
return Map();
|
||||
}
|
||||
@ -36,7 +36,7 @@ const jsToMap = (obj: {}) => {
|
||||
throw new Error('Object must be equivalent to a Map.');
|
||||
}
|
||||
return immutableObj;
|
||||
};
|
||||
}
|
||||
|
||||
const knownMetaKeys = Set([
|
||||
'index',
|
||||
@ -49,8 +49,10 @@ const knownMetaKeys = Set([
|
||||
'folder',
|
||||
'depth',
|
||||
]);
|
||||
const filterUnknownMetaKeys = (meta: Map<string, string>) =>
|
||||
meta.filter((_v, k) => knownMetaKeys.has(k as string));
|
||||
|
||||
function filterUnknownMetaKeys(meta: Map<string, string>) {
|
||||
return meta.filter((_v, k) => knownMetaKeys.has(k as string));
|
||||
}
|
||||
|
||||
/*
|
||||
createCursorMap takes one of three signatures:
|
||||
@ -58,7 +60,7 @@ const filterUnknownMetaKeys = (meta: Map<string, string>) =>
|
||||
- (cursorMap: <object/Map with optional actions, data, and meta keys>) -> cursor
|
||||
- (actions: <array/List>, data: <object/Map>, meta: <optional object/Map>) -> cursor
|
||||
*/
|
||||
const createCursorStore = (...args: {}[]) => {
|
||||
function createCursorStore(...args: {}[]) {
|
||||
const { actions, data, meta } =
|
||||
args.length === 1
|
||||
? jsToMap(args[0]).toObject()
|
||||
@ -71,15 +73,18 @@ const createCursorStore = (...args: {}[]) => {
|
||||
data: jsToMap(data),
|
||||
meta: jsToMap(meta).update(filterUnknownMetaKeys),
|
||||
}) as CursorStore;
|
||||
};
|
||||
}
|
||||
|
||||
const hasAction = (store: CursorStore, action: string) => store.hasIn(['actions', action]);
|
||||
function hasAction(store: CursorStore, action: string) {
|
||||
return store.hasIn(['actions', action]);
|
||||
}
|
||||
|
||||
const getActionHandlers = (store: CursorStore, handler: ActionHandler) =>
|
||||
store
|
||||
function getActionHandlers(store: CursorStore, handler: ActionHandler) {
|
||||
return store
|
||||
.get('actions', Set<string>())
|
||||
.toMap()
|
||||
.map(action => handler(action as string));
|
||||
}
|
||||
|
||||
// The cursor logic is entirely functional, so this class simply
|
||||
// provides a chainable interface
|
||||
|
Reference in New Issue
Block a user