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

The methods in arrProxy did not return, such as sort, which resulted in an undefined being returned #181

Open
hsuna opened this issue Jan 26, 2024 · 3 comments
Labels
low priority Done later

Comments

@hsuna
Copy link

hsuna commented Jan 26, 2024

function arrProxy(arr) {
const { unshift, splice, push, sort, reverse } = arr
return Object.assign(arr, {
// adding
push(item) {
push.call(items, item)
mountItem(item, items.length - 1)
},
unshift(item) {
unshift.call(items, item)
mountItem(item, 0, null, blocks[0].$el)
},
// sorting
sort(fn) {
sort.call(items, fn)
repaint()
},
reverse() {
reverse.call(items)
repaint()
},
// removing
splice(i, len) {
blocks.slice(i, i + len).forEach(el => el.unmount())
blocks.splice(i, len)
splice.call(items, i, len)
},
shift() { arr.splice(0, 1) },
pop() { arr.splice(arr.length -1, 1) },
// handy shortcut for a common operation
remove(item) {
const i = items.indexOf(item)
if (i >= 0) arr.splice(i, 1)
}
})
}

@tipiirai
Copy link
Contributor

What does the source code of the component look like?

@hsuna
Copy link
Author

hsuna commented Jan 29, 2024

version:0.3.3

app.nue

<div @name="app">
    <div :for="item in list" @click="handleClick">
        {item}
    </div>

    <script>
        list = [1, 3, 2];
        handleClick() {
            console.log('right => ', [...this.list].sort((a, b) => a - b));
            console.log('wrong =>', this.list.sort((a, b) => a - b));
        }
    </script>
</div>

click number,console output:
image

After conversion, using native methods is correct, but using proxy methods returns undefined.

@tipiirai tipiirai added the low priority Done later label Jan 31, 2024
@tipiirai
Copy link
Contributor

Nice. This helps! Note that I added a low priority tag here, since the single-page application stuff comes later on my personal todo list. I'm following this roadmap. Thanks

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

No branches or pull requests

2 participants