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

remove should pass through the value #3

Open
mcollina opened this issue May 26, 2014 · 0 comments
Open

remove should pass through the value #3

mcollina opened this issue May 26, 2014 · 0 comments

Comments

@mcollina
Copy link

As for supporting the 'list' patrun as depicted in the README, it's not currently possible to remove elements in sparse order.

var patrun = require('patrun')
  , many = patrun( function(pat,data){
      var items = this.find(pat,true) || []
      items.push(data)

      return {
        find: function(args,data){
          console.log('find', arguments)
          return 0 < items.length ? items : null
        },
        remove: function(args,data){
          // data is always 'A'
          items.pop()
          return 0 == items.length;
        }
      }
    })

many.add( {a:1}, 'A' )
many.add( {a:1}, 'B' )

many.remove( {a:1}, 'A' )
console.log(many.find( {a:1} )) // should be [ 'B' ], but is 'A'

I suggest that the custom remove should include a way for passing the dest value through the remove call.

Moreover, I think the following line https://github.com/rjrodger/patrun/blob/master/patrun.js#L92 should be changed: it's impossible to remove the original data through the custom remove function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants