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

behaviour of ractive.toggle('foo.*.bar') #1604

Closed
Rich-Harris opened this issue Dec 23, 2014 · 2 comments
Closed

behaviour of ractive.toggle('foo.*.bar') #1604

Rich-Harris opened this issue Dec 23, 2014 · 2 comments

Comments

@Rich-Harris
Copy link
Member

This SO question raises an interesting point: should ractive.toggle(), if used with a keypath pattern like foo.*.bar, toggle all the keypaths that match that pattern?

At present, it's just a simple wrapper around ractive.set():

// this...
ractive.toggle( 'foo.*.bar' );

// ...is equivalent to this...
ractive.set( 'foo.*.bar', !this.get( 'foo.*.bar' ) );

// ...which is equivalent to this. Not very helpful
ractive.set( 'foo.*.bar', true );

Possibly a niche use case but it does break expectations. The ractive.add() and ractive.subtract() convenience methods are in the same boat, though that's even more niche.

@Madgvox
Copy link
Member

Madgvox commented Dec 24, 2014

I think it makes the most sense (and I think this how I thought of it in my mind) for wildcard keypaths to act like a forEach would.

console.log( ractive.get( 'foo' ) ); // -> [ { bar: true }, { bar: false }, { bar: true } ]

ractive.toggle( 'foo.*.bar' );

console.log( ractive.get( 'foo' ) ); // -> [ { bar: false }, { bar: true }, { bar: false } ]

@fskreuz
Copy link
Contributor

fskreuz commented Dec 27, 2014

I think it should, if one assumes that foo is an array and * means indexes.

Wild question: What happens if foo was an object, and * means properties of an object? Should it set bar inside them? One could probably defer this as an end-user responsibility, but then... :trollface:

@Rich-Harris Rich-Harris added this to the 0.7.0 milestone Mar 10, 2015
Rich-Harris added a commit that referenced this issue Mar 10, 2015
Rich-Harris added a commit that referenced this issue Mar 10, 2015
Allow wildcards to be used with ractive.toggle(), ractive.add() and ractive.subtract()
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

3 participants