Skip to content

Provide an id utility to extract the seed value of a node #134

Description

@drborges

In front-end apps, often the need for a UUID comes up to be able to uniquely identify values in the absence of a backend DB ID.

Since Arbor already assigns a unique Seed value to nodes so it can track them across mutations (even when using ImmutableArbor that applies structural sharing to the underlying data), the idea is to expose that value so users can use it to uniquely identify values in their application state without the need to create UUIDs.

Example:

import { id } from "@arborjs/store"

const store = new Arbor([
  { text: "todo 1" },
  { text: "todo 2" },
])

const arrayId = id(store.state)
=> 0
const todo1Id = id(store.state[0])
=> 1
const todo2Id = id(store.state[1])
=> 2

This can be handy in React apps to use as keys to components.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions