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

feat(service): handle flash object preventDuplicates similar to global option #282

Merged
merged 1 commit into from Jun 15, 2020

Conversation

makepanic
Copy link
Contributor

fixes #281

Everything open for discussion :)

@@ -140,7 +142,8 @@ export default Service.extend({
},

_enqueue(flashInstance) {
const preventDuplicates = get(this, 'defaultPreventDuplicates');
const preventDuplicates = get(this, 'defaultPreventDuplicates') ||
get(flashInstance, 'preventDuplicates');

Choose a reason for hiding this comment

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

I'd have imagined that the option on the flashInstance itself should trump the global setting as it's more specific. This would not be the case with the above logic. What's the intention?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, that makes more sense.
I'll change it soon

@makepanic
Copy link
Contributor Author

I've made some changes so it'll always prefer the instance option over the global one.
Also rebased onto latest master

@@ -30,6 +31,10 @@ export function guidFor(dependentKey) {
get() {
const value = get(this, dependentKey);

// it's possible that a value has no toString as some objects don't implement the guid field
// this early return it to avoid errors being thrown when calling undefined.toString()
if (isNone(value)) return;

Choose a reason for hiding this comment

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

Perhaps just checking if (typeof value.toString !== "function") would show your intention more obviously?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sadly it would require additional checks as typeof undefined.toString will throw an error:

Uncaught TypeError: Cannot read property 'toString' of undefine

@makepanic
Copy link
Contributor Author

I've rebased this PR onto the current master

@makepanic
Copy link
Contributor Author

@sbatson5 @abhilashlr do you think we could also merge/work on this PR?

We used it since 2018 in production and haven't seen any issues.

If so, I'll check if I can find anything to improve. Right now it's only rebased onto the current master.

@abhilashlr
Copy link
Contributor

@sbatson5 Seems like the PR has test cases passing. If this is fine, I think we should merge it?

@sarus
Copy link

sarus commented Jun 4, 2020

Would really love to see this capability.

@alexdiliberto
Copy link

Is there anything specific which is preventing this from being merged?

@makepanic
Copy link
Contributor Author

Rebased it onto the current master

@sbatson5 sbatson5 merged commit 080bff5 into adopted-ember-addons:master Jun 15, 2020
@makepanic makepanic deleted the issues/281 branch December 8, 2020 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow setting preventDuplicates when adding a flash message
7 participants