3

Scenario:

For ex, you define a schema in realm-js as:

export const businessSchema = {
  name: 'Business',
  primaryKey: 'id',
  properties: {
    id: 'int',
    number_of_stores_in_cities: 'int[]',
  }
}

You have already created an object of Business and saved to Realm. Then have queried this object somewhere else. And you want to copy this field number_of_stores_in_cities to javascript array js_number_of_store_in_cities for further processing.

What I expect: Realm has defined handlers to get the entire target list which I can simply call it like number_of_stores_in_cities.all() or number_of_stores_in_cities.getList() in the Proxy

What I have: Seems like they didn't define these handlers for what I expect. And their getters are defined based on index of an array. So this proxy number_of_stores_in_cities works exactly like a javascript array. I tried to copy entries one by one from number_of_stores_in_cities to js_number_of_stores_in_cities. I've also tried const js_number_of_stores_in_cities = Array.prototype.slice.call(number_of_stores_in_cities). However, both of the methods are unexpectedly slow such that they took roughly 10 seconds to copy a length of 2500 list.

What I need: Instead of using these traditional javascript array methods, is there a way that I can get a plain javascript array from the Proxy in a fast fashion? Do I need to provide my handler to this Proxy?

enter image description here

RandomEli
  • 1,527
  • 5
  • 30
  • 53

0 Answers0