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

Methods that return new objects (.map, .filter) should be proxied as well. #40

Closed
mjstahl opened this issue Jun 25, 2019 · 3 comments
Closed

Comments

@mjstahl
Copy link
Contributor

mjstahl commented Jun 25, 2019

const proxied = onChange([1, 2, 3], function () { ... })
const notProxied = proxied.filter(x => x > 1)

I think we might have to use Symbol.species but not completely sure yet.

@mjstahl
Copy link
Contributor Author

mjstahl commented Jun 25, 2019

I tried this out in a repl, and seems to work nicely. I am not sure how integrate these ideas generically.

class ProxiedArray extends Array {
    static get [Symbol.species]() {
        return proxy // the proxy created around 219
    }
}

@DarrenPaulWright
Copy link
Collaborator

The new object that is returned is just that, a new object. If you modify the new object, then
you are not modifying the target object, so I would not expect the callback to be called.

Can you provide a use case for what your asking?

@mjstahl
Copy link
Contributor Author

mjstahl commented Jul 11, 2019

Oh sure. It might be out of scope, but I figured I would bring it up to see what other's thought.

import onChange from 'on-change'

const listOf = [1, 2, 3, 4]
const proxied = onChange(listOf, function () { ... })

// or splice, map, or any other Array.prototype function that returns a new Array
const filtered = proxied.filter(() => { ... })

The use case is filtered being a Proxy with the same "callback" as proxied.

@mjstahl mjstahl closed this as completed Nov 1, 2019
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

No branches or pull requests

2 participants