Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: minor, non-functional changes #876

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmrc
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For devs that use private NPM registries. Avoid conflicts with commands like npm publish

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry = "https://registry.npmjs.org"
24 changes: 1 addition & 23 deletions src/effects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, isPromise } from './lib';
import { get, handleEventDispatchErrors, isPromise } from './lib';

export function createEffectsMiddleware(_r) {
return (store) => (next) => (action) => {
Expand Down Expand Up @@ -87,28 +87,6 @@ export function createEffectHandler(def, _r, injections, _aC) {
};
}

const logEffectEventListenerError = (type, err) => {
// eslint-disable-next-line no-console
console.log(`Error in ${type}`);
// eslint-disable-next-line no-console
console.log(err);
};

const handleEventDispatchErrors =
(type, dispatcher) =>
(...args) => {
try {
const result = dispatcher(...args);
if (isPromise(result)) {
result.catch((err) => {
logEffectEventListenerError(type, err);
});
}
} catch (err) {
logEffectEventListenerError(type, err);
}
};

export function createEffectActionsCreator(def, _r, effectHandler) {
const actionCreator = (previousDependencies, nextDependencies, action) => {
const change = {
Expand Down
4 changes: 0 additions & 4 deletions src/extract-data-from-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export default function extractDataFromModel(
const _aCD = {};
const _aC = {};
const _aRD = {};
const actionThunks = {};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, this was never being used. All tests still pass.

const _cP = [];
const _cR = [];
const _e = [];
Expand Down Expand Up @@ -126,9 +125,6 @@ export default function extractDataFromModel(
// the thunk action is created/dispatched
def.thunkHandler = createThunkHandler(def, _r, injections, _aC);

// Register the thunk handler
set(path, actionThunks, def.thunkHandler);

Comment on lines -129 to -131
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we don't have tests covering this? IDK what actionThunks are

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this branch against our codebase, and we get 0 failures - so I guess this is fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is related to this change: #876 (comment). The only place actionThunks was ever being used was here, the thunkHandler was being set on the object but then the object never got passed along to anything else. And if all the tests still pass, I'm thinking it's fine. Ctrl + Shift + F also turned up no other references to actionThunks. Obviously this isn't definitive because it could be passed to a func that calls it something else, but if deleting this line doesn't break anything else I think we're good.

// Create the "action creator" function
def.actionCreator = createThunkActionsCreator(def, _r);

Expand Down
22 changes: 22 additions & 0 deletions src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,25 @@ export function useMemoOne(

return cache.result;
}

const logEventListenerError = (type, err) => {
// eslint-disable-next-line no-console
console.log(`Error in ${type}`);
// eslint-disable-next-line no-console
console.log(err);
};

export const handleEventDispatchErrors =
(type, dispatcher) =>
(...args) => {
try {
const result = dispatcher(...args);
if (isPromise(result)) {
result.catch((err) => {
logEventListenerError(type, err);
});
}
} catch (err) {
logEventListenerError(type, err);
}
};
Comment on lines +216 to +236
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the code a bit more DRY by replacing repeated code with shared util.

6 changes: 3 additions & 3 deletions src/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const noopStorage = {
removeItem: () => undefined,
};

const getBrowerStorage = (storageName) => {
const getBrowserStorage = (storageName) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops!

let storageCache;
return () => {
if (!storageCache) {
Expand All @@ -30,8 +30,8 @@ const getBrowerStorage = (storageName) => {
};
};

const localStorage = getBrowerStorage('localStorage');
const sessionStorage = getBrowerStorage('sessionStorage');
const localStorage = getBrowserStorage('localStorage');
const sessionStorage = getBrowserStorage('sessionStorage');

function createStorageWrapper(storage, transformers = [], migrations = {}) {
if (storage == null) {
Expand Down
24 changes: 1 addition & 23 deletions src/thunks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { thunkOnSymbol } from './constants';
import { get, isPromise } from './lib';
import { get, handleEventDispatchErrors, isPromise } from './lib';

export function createThunkHandler(def, _r, injections, _aC) {
return (payload, fail) => {
Expand All @@ -23,28 +23,6 @@ export function createThunkHandler(def, _r, injections, _aC) {
};
}

const logThunkEventListenerError = (type, err) => {
// eslint-disable-next-line no-console
console.log(`Error in ${type}`);
// eslint-disable-next-line no-console
console.log(err);
};

const handleEventDispatchErrors =
(type, dispatcher) =>
(...args) => {
try {
const result = dispatcher(...args);
if (isPromise(result)) {
result.catch((err) => {
logThunkEventListenerError(type, err);
});
}
} catch (err) {
logThunkEventListenerError(type, err);
}
};

export function createThunkActionsCreator(def, _r) {
const actionCreator = (payload) => {
const dispatchStart = handleEventDispatchErrors(def.meta.startType, () =>
Expand Down
Loading