https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • g

    Greylock

    06/29/2021, 3:22 PM
    > To access a Durable Object from a worker, you must first configure the worker with a binding for a Durable Object namespace. The namespace is, in turn, configured to use a particular class, and controls access to instances of that class.
  • g

    Greylock

    06/29/2021, 3:22 PM
    @User do you know how to configure a binding?
  • w

    Wallacy

    06/29/2021, 3:24 PM
    well... you do that on the wrangler.toml -> [durable_objects] bindings = [ { name = "Counter", class_name = "Counter" } ]
  • g

    Greylock

    06/29/2021, 3:25 PM
    ohh
  • g

    Greylock

    06/29/2021, 3:26 PM
    but how do I create a new unique ID?
  • w

    Wallacy

    06/29/2021, 3:27 PM
    you dont need, just name e class_name
  • g

    Greylock

    06/29/2021, 3:27 PM
    do I do ``env.rooms.newUniqueId()``?
  • g

    Greylock

    06/29/2021, 3:28 PM
    or do I do ``Counter.newUniqueId()``
  • w

    Wallacy

    06/29/2021, 3:28 PM
    ohh... you can do that too
  • g

    Greylock

    06/29/2021, 3:28 PM
    which?
  • g

    Greylock

    06/29/2021, 3:28 PM
    I tried ``env.rooms`` but it said it was undefined
  • w

    Wallacy

    06/29/2021, 3:28 PM
    env.rooms.newUniqueId() if rooms is you binding
  • g

    Greylock

    06/29/2021, 3:28 PM
    ah
  • w

    Wallacy

    06/29/2021, 3:28 PM
    the "name" is the name of the binding
  • g

    Greylock

    06/29/2021, 3:29 PM
    ah
  • g

    Greylock

    06/29/2021, 3:29 PM
    I didnt read the header
  • g

    Greylock

    06/29/2021, 3:29 PM
    of the chat demo
  • g

    Greylock

    06/29/2021, 3:29 PM
    the comment said that
  • g

    Greylock

    06/29/2021, 3:30 PM
    cool
  • g

    Greylock

    06/29/2021, 3:33 PM
    still not working
  • g

    Greylock

    06/29/2021, 3:33 PM
    I have the bindings but ``env.[binding]`` is still undefined
  • g

    Greylock

    06/29/2021, 3:33 PM
    Copy code
    toml
    bindings = [
        { name = "rooms", class_name= "ChatRoom" },
        { name = "limiters", class_name = "RateLimiter" }
    ]
  • g

    Greylock

    06/29/2021, 3:34 PM
    ie theres my bindings but ``env.rooms`` is still undefined
  • g

    Greylock

    06/29/2021, 3:37 PM
    Copy code
    Cannot read property 'newUniqueId' of undefined
  • g

    Greylock

    06/29/2021, 3:37 PM
    but my esbuild bundle output does indeed have the exports:
  • g

    Greylock

    06/29/2021, 3:37 PM
    Copy code
    js
    export {
      ChatRoom,
      RateLimiter,
      entry_default as default
    };
  • g

    Greylock

    06/29/2021, 3:37 PM
    in the bundle
  • g

    Greylock

    06/29/2021, 3:38 PM
    so, im not really sure what to do?
  • g

    Greylock

    06/29/2021, 3:38 PM
    is this a bug?
  • g

    Greylock

    06/29/2021, 3:42 PM
    Copy code
    json
    {
      "result": {
        "id": "coincrash_test",
        "etag": "SOME ETAG",
        "handlers": [
          "fetch"
        ],
        "named_handlers": [
          {
            "name": "ChatRoom",
            "handlers": [
              "class"
            ]
          },
          {
            "name": "RateLimiter",
            "handlers": [
              "class"
            ]
          }
    }
1...114115116...567Latest