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

reactive/bindable **Iterable** data structure #65

Open
Tracked by #8
DrSensor opened this issue Mar 21, 2023 · 2 comments
Open
Tracked by #8

reactive/bindable **Iterable** data structure #65

DrSensor opened this issue Mar 21, 2023 · 2 comments
Labels
data binding Everything related to data binding optimization Because speed, memory consumption, and bundle size are important
Milestone

Comments

@DrSensor
Copy link
Owner

DrSensor commented Mar 21, 2023

This replace/shim JS Array, Map, and Set with nusa/std Vector, Map, Set.

import { Vector as Vec, Map, Set } from "//esm.run/nusa/std/collections"

export default {
  coins = new Vec<number>()
  makets = new Map<string, number>()
  symbols = new Set<string>()

  shuffleLastCoin() {
    console.debug("previous last coin", this.coins.at(-1))
    this.coins.setAt(-1, dice([100, 300], [10, 50]))
  }
}

Yes, indexing operator (i.e arr[i]) is not reactive and there is no way to override/overload it in JS. That's why the name is Vector, not Array.

@DrSensor DrSensor changed the title reactive bindable Iterable data structure reactive/bindable **Iterable** data structure Mar 21, 2023
@DrSensor DrSensor added data binding Everything related to data binding optimization Because speed, memory consumption, and bundle size are important labels Mar 21, 2023
@DrSensor
Copy link
Owner Author

DrSensor commented Mar 21, 2023

Also, supporting plain Object as Dictionary might be a good idea since it get optimized as long as the keys < 32. Although Map is superior than plain Object, plain Object get optimized most of the time.

export class Dictionary<T extends Record<infer K, infer V>> implements Map<K, V> {
  #data: T
  constructor(data: T = {}) {
    this.#data = data
  }
}

@DrSensor
Copy link
Owner Author

DrSensor commented May 11, 2023

The more I think about making reactive ES data type, the more it give me a headache when I want to make the memory contiguous 😅

Alright, I should start with Arrow data type first then map it 1:1 into ES data type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data binding Everything related to data binding optimization Because speed, memory consumption, and bundle size are important
Development

No branches or pull requests

1 participant