All Questions
16
questions
0
votes
1
answer
30
views
Multiple Access to two-dimensional array (using setters/getter via Proxy or Object.defineProperty)
I have a two dimensional array that I need to perform read and write action on from various angles.
Sometimes I need to get/set a single row (easy of course) and sometimes I need to get/set a single ...
0
votes
0
answers
77
views
Trap array changes (add/delete) inside object of proxy
I am trying to track some array changes inside of proxyfied object.
For example:
object = {
count: 0,
input: ``,
tasks: [ ]
}
and I need to track changes of object.tasks.
The problem ...
0
votes
2
answers
57
views
JavaScript proxies : aggregate notifications after array sort
I would like to find a way to get only one notification after an array sort
Is there a way? Thank you
const callback = function () {
console.log (...arguments)
}
const array = [2,1]
const handler = {...
1
vote
1
answer
66
views
For an instance field which is an array value, how does one handle additional tasks whenever the array mutates by e.g. pushing into or splicing it?
The set accessor does not take place whenever one does mutate the Crumbs class property value by e.g pushing into it.
I'm trying to create a class property via set syntax which I expect to handle an ...
1
vote
0
answers
527
views
trying to set Proxy trap for a nested object. succeeded intercession except array.unshift and array.splice and some others
i am trying to make a Proxy trap for a nested object (kinda trying to implement vuex reactive).
kinda succeeded in setting trap following this post:
How to use javascript proxy for nested objects
my ...
22
votes
3
answers
50k
views
how to get an array out of a javascript proxy
I was wondering how to get an array out of a proxy's target value in JavaScript. I have something like this :
Proxy :
[[target]] : Array // the array I need to extract
[[handler]] : Object
[[...
-1
votes
2
answers
1k
views
JavaScript Proxy which returns an empty array by default
I want to define some object so that every property provides an empty array if it's not defined.
Example: consider the list of users, every user is {id: number, age: string, ...}. We want to group ...
1
vote
0
answers
959
views
Observe array with Proxy (adding and removing items)
I'm playing around with Proxys and my goal is to obeserve operations on some array. In particular I want to run some code whenever items are being added or removed. The example that I currently have ...
3
votes
1
answer
644
views
Why is [[GetPrototypeOf]] an Invariant of a Javascript Proxy?
One application for a Javascript Proxy object is to reduce network traffic by sending data over the wire as an array of arrays, along with an object listing the field names and index of each field (ie....
8
votes
2
answers
2k
views
How to get deleted or inserted item from proxy array?
I am trying to detect changes in an array of objects using JavaScript proxies.
Problem: Any time there is a change in array like deletion or insertion, i want to get that deleted or inserted item.
...
2
votes
0
answers
2k
views
How to watch an Array for changes in JS
I understand there used to be Array.observe() which is now deprecated in favor of Proxies. I read the documentation on proxy traps, but I guess I feel it's pretty brittle for arrays... like let's say ...
16
votes
1
answer
6k
views
Properly building Javascript proxy set handlers for arrays
What is the correct way to build Javascript proxies for arrays so that 'set' handlers do not get invoked multiple times for a single change to the array?
Here is what I mean:
I want to wrap a simple ...
0
votes
1
answer
93
views
How to get the deleted item (for post-handling by proxy) if `length` property of array was decreased directly?
JavaScript (ECMAScript 6)
I wrote a proxy for Array item. I do it for solving the problem... I show this problem on the base of such example:
function Node(value){
this.parent = null; // parent ...
1
vote
1
answer
587
views
Rejecting array inputs with JS Proxy
I want to create an array that only accepts a certain instance type to be stored. It seems the best solution was to use Proxies, inspired by this gist and SO thread.
So I have a proxy working and for ...
2
votes
1
answer
383
views
JavaScript Proxies: set does not trigger when modifying objects in an array
I have an array filled with objects
let array_of_objects = [{
id: 1,
name: "John"
}, {
id: 2,
name: "Bill"
}, {
id: 3,
name: "Mike"
}];
I then create a proxy with a set handler and my ...