Open igorissen opened 7 months ago
Your proposal to introduce a pop()
method as an alternative to get()
sounds promising. Here's a brief outline of the proposed method and its functionality:
pop()
Method:/**
* Retrieves and removes the value associated with the specified key from the request yar store.
* @param {string} key - The key to retrieve and remove from the store.
* @returns {*} The value associated with the key if it exists; otherwise, null.
*/
request.yar.pop = function(key) {
// Logic to retrieve and remove the value associated with the key from the store
// Return the value if it exists, otherwise return null
};
// Example of using the proposed pop() method
const value = request.yar.pop('key');
if (value !== null) {
// Handle the retrieved value
} else {
// Key does not exist in the store
}
pop()
method provides a clear indication of its functionality, similar to the Array.prototype.pop()
method in JavaScript.pop()
method intuitive to use.pop()
method behaves as expected in different scenarios and edge cases.pop()
method and provide usage examples for developers.By incorporating the pop()
method, developers can benefit from improved clarity and ease of use when interacting with the request yar store in the Pix project. If you encounter any issues or have further suggestions, feel free to iterate on the proposal and collaborate with the project team for enhancements.
Runtime
nodejs
Runtime version
20.10.0
Module version
11.0.1
Used with
hapi
Any other relevant information
No response
What problem are you trying to solve?
Currently, my colleagues and I are using your plugin on this project Pix, and we've noticed that the use of the method
get()
isn't clear, especially when someone unfamiliar with the plugin sees this linerequest.yar.get('key', true);
.It's not clear what the value
true
means. For that we need to go to the documentation page. It will be great to use something likepop('key')
.We think that as JavaScript developers we will somehow see more frequently this method
pop
used with arrays.Do you have a new or modified API suggestion to solve the problem?
This method
pop()
will have an argument which is thekey
and will removes the key if it is available in the store. If the key does not exist, it will returnnull
as value.I have created a PR #167