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

add chainable method for returning flash object #214

Merged
merged 1 commit into from
Nov 30, 2016

Conversation

sbatson5
Copy link
Collaborator

@sbatson5 sbatson5 commented Oct 31, 2016

What's in this PR

This should address the issue raised by #154. A fluent API allows for chaining methods, but does not give access to the flash object. For users who want to manipulate the object directly, they can access it with the getFlashObject method, which will return the last object added to the queue.

  • Add chainable method that returns the flash object
  • Add test coverage in service test
  • Update Readme to include documentation on getFlashObject

@sbatson5 sbatson5 force-pushed the add-getFlashObject-method branch 2 times, most recently from 6cb5be7 to ff85f7f Compare October 31, 2016 16:02
@@ -68,6 +68,13 @@ export default Service.extend({
return this;
},

getFlashObject() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@poteto Thoughts on if this is acceptable based on the existing pattern? Addresses #154 but it isn't quite as fluent. Also, thoughts on renaming to getLastFlashObject since it is a public method and could be called anywhere?

Copy link

@panthony panthony Nov 18, 2016

Choose a reason for hiding this comment

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

IMO getLastFlashObject holds more meaning than getFlashObject.

Or since we are talking about a queue of message, why not provide accessors such as peekFirst and peekLast ?

They would return undefined for an empty queue

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@panthony trying to wrap this up today. I like peekLast and peekFirst but what about a specific index? Or should we not worry about that?

I kind of like getFlashObject because it implies that it is chainable and returns the flash object we just added. If someone wants to get a specific index, they can access the queue from the service directly.

Choose a reason for hiding this comment

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

@sbatson5 well I first I though of peekAt(idx) that would be called by peekFirstand peekLast but it was maybe too much as the requirement was only to retrieve the last.

Copy link

@panthony panthony Nov 30, 2016

Choose a reason for hiding this comment

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

Here's my current implem:

cogniteev@21727b0

And as I reviewed again I just noticed that I have an unnecessary call to get(this, 'queue') ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Awesome!

I'm thinking of maybe having all 3 methods. I like the readability of:
flash.add({ message: 'foo' }).getFlashObject(); as it returns the object we just added. peekLast doesn't make sense to chain.

Then we can still have peekLast and peekFirst but encourage that they aren't chainable but are public calls to our service.

Thoughts?

@homu
Copy link
Contributor

homu commented Nov 30, 2016

☔ The latest upstream changes (presumably 29351d4) made this pull request unmergeable. Please resolve the merge conflicts.

@sbatson5 sbatson5 force-pushed the add-getFlashObject-method branch from ff85f7f to 9693974 Compare November 30, 2016 16:16
@sbatson5
Copy link
Collaborator Author

@panthony let me know what you think of a395f2c

@panthony
Copy link

@sbatson5 wow I was not aware of the firstObject and lastObject accessor. That's pretty convenient. Never too late to learn something.

I'd say that maybe getFlashObject is redundant but it's a matter of taste I guess. Not sure why peekXXX would be 'less chainable'.

And didn't you say that getLastFlashObject was better ?

Or maybe rename peekXXX by get{First|Last}FlashObject so that you have the context of what you get no matter where you call the method ?

@sbatson5
Copy link
Collaborator Author

sbatson5 commented Nov 30, 2016

@panthony I'm just thinking of the naming convention: flashMessageService.add(object).getFlashObject seems readable to me as it returns the object I just added.

flashMessageService.add(object).peekLast seems like I am adding an object and then looking at the last one in the queue for some reason. We understand the context of how the queue works, but if you were new to this addon and read that, it wouldn't be clear why you would do it that way. The name doesn't imply that we are returning the result of our add. So in essence, getFlashObject is just an alias of peekLast but I think it is a bit more idiomatic when we are chaining.

@sbatson5 sbatson5 force-pushed the add-getFlashObject-method branch from a395f2c to 0369c6a Compare November 30, 2016 18:41
@panthony
Copy link

@sbatson5 Ok ! So this is looking great in that case :)

add peek methods to return first and last objects
@sbatson5 sbatson5 force-pushed the add-getFlashObject-method branch from 0369c6a to 10032d5 Compare November 30, 2016 21:05
@sbatson5 sbatson5 merged commit 9d844a4 into master Nov 30, 2016
@sbatson5 sbatson5 deleted the add-getFlashObject-method branch November 30, 2016 21:12
This was referenced Dec 2, 2016
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.

3 participants