-
Notifications
You must be signed in to change notification settings - Fork 79
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
how to remove an object from collection #26
Comments
a nice |
Cool idea! Let's name it |
Lockr.srempos or Lockr.sremat would be nice! If you can go further, how about something like Lockr.srem("cart", {id: 123}) ? |
Just clarifying |
I understand the example when the item to add is primitive data like below: How to do if the Lockr.sadd does not work on primitive data as 1, 2 but object like {id: 123, name: abc}? |
Indeed, it doesn't work currently for objects like this yet. I was referring to the existing functionality of |
@hungcaoduy @tsironis True, I confirm this as a bug. The reason behind this is that I'll craft a patch tomorrow as well as add some regression tests. Thanks for reporting! PS: As for |
@eavgerinos what we would be a Redis-like method name for |
ping @eavgerinos |
@tsironis http://redis.io/commands#set nope AFAIK. IMHO, we should fix the behavior of |
I just ran into this dilemma myself. Anyone ever got it fixed? |
This is not fixed yet. Temporary solution is the one mentioned by @choval though. |
I take it this issue hasn't been resolved as yet. |
any incoming good news for this issue? |
Hello everyone. Here's a working implementation from srempos. You can use the index that matches the smembers array. Lockr.srem = function(key, value, options, positionToRemove)
{
var query_key = this._getPrefixedKey(key, options), json,index;
var values = Lockr.smembers(key, value);
if (positionToRemove !== undefined)
{
index = positionToRemove;
}
else index = values.indexOf(value);
if ((index > -1) && (index < values.length))
values.splice(index, 1);
json = JSON.stringify({"data": values});
try {
localStorage.setItem(query_key, json);
} catch (e) {
if (console) console.warn("Lockr couldn't remove the "+ value +" from the set "+ key);
}
};
Lockr.srempos = function(key, pos) {
return Lockr.srem(key, undefined, undefined, pos)
}; |
I added my product into shopping cart by using:
Lockr.sadd("cart", {id: 123, name: abc});
Lockr.sadd("cart", {id: 456, name: def});
How to remove a particular object from cart? e.g I later want to remove the first object {id: 123, name: abc}
thanks
The text was updated successfully, but these errors were encountered: