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

    brett

    04/05/2021, 9:52 PM
    For now you can follow the initialize pattern here: https://developers.cloudflare.com/workers/learning/using-durable-objects#example---counter
  • j

    jed

    04/05/2021, 10:08 PM
    given how common this issue is, I wonder if it would make more sense for
    new Date
    to throw in global scope instead of silently returning unanticipated values.
  • g

    Greg Brimble | Cloudflare Pages

    04/05/2021, 10:09 PM
    Could there be a valid use-case of having just a Date object in the global state though?
  • g

    Greg Brimble | Cloudflare Pages

    04/05/2021, 10:09 PM
    Not necessarily set to the current time, but for just manipulating an explicit datetime?
  • k

    Kevin W - Itty

    04/05/2021, 10:45 PM
    Any interest in a helper class (called DurableObject in this example) that allows this sort of internal syntax/flow in durable objects? fetch call, storage persistance/initialization, etc are abstracted away
  • j

    john.spurlock

    04/05/2021, 10:46 PM
    surprised to see that there is no option to list() only the keys from DO storage, without also reading the associated values. the values are small, but still a waste of read $$$. Maybe a new property in the options object to control this? https://developers.cloudflare.com/workers/runtime-apis/durable-objects#methods
  • b

    brett

    04/05/2021, 10:47 PM
    You should still be able to construct a specific date (a la
    new Date(1995, 11, 17, 3, 24, 0)
    ), and you can always check for undefined and set a global var with a date on the first request if you want to store a
    new Date
    in global scope
  • k

    Kevin W - Itty

    04/05/2021, 10:48 PM
    would def have preferred this...
  • k

    Kevin W - Itty

    04/05/2021, 10:51 PM
    although i have no such trouble using the constructor to embed other instantiation-specific data... and it later persists and initializes just fine. it's only the date that has issues
  • j

    jed

    04/05/2021, 11:17 PM
    definitely, but perhaps new Date without arguments should throw.
  • j

    jed

    04/05/2021, 11:18 PM
    (same for Date.now too)
  • g

    Greg Brimble | Cloudflare Pages

    04/05/2021, 11:34 PM
    Got something similar myself. Would certainly be interested to see your implementation!
  • g

    Greg Brimble | Cloudflare Pages

    04/05/2021, 11:37 PM
    I don't have super strong opinions on it, but I think I have a slight preference for the current behavior.
  • h

    haneefmubarak

    04/05/2021, 11:41 PM
    I concur; it would be bizarre and not inline with the usual behavior at all for either
    new Date()
    or
    Date.now()
    to throw...
  • j

    jed

    04/06/2021, 12:15 AM
    i don’t think returning a date in 1970 could be described as the usual behavior either. the question is whether you want to let the user know about the unstandard behavior in the worker or here in discord. 😛
  • g

    Greg Brimble | Cloudflare Pages

    04/06/2021, 12:16 AM
    Fair point. Would a warning in the proper docs be enough, do you think?
  • j

    jed

    04/06/2021, 12:16 AM
    a more intuitive behavior would be to use the last modified date of the source or last instantiation of the worker, but i understand you guys have reasons not to do that.
  • k

    Kevin W - Itty

    04/06/2021, 12:28 AM
    there some reason we can't bind methods in a durable object? when I do, I get this:
  • k

    Kevin W - Itty

    04/06/2021, 12:29 AM
    that's just from doing something like this in a constructor:
  • j

    jed

    04/06/2021, 12:30 AM
    i prefer the API to reflect the platform (ie does `fetch`ing an IP address throw or return an empty response? does
    new Function
    throw or return an empty function?), but consolidating the areas where workers stray from standard behavior is definitely a good idea.
  • u

    Unsmart | Tech debt

    04/06/2021, 12:53 AM
    I dont think that would work in any case durable objects or not. You are assigning this.incrementCounter to itself with bind(this). If it does work without durable objects honestly have no clue how thats possible.
  • m

    matt

    04/06/2021, 2:28 AM
    Has anyone tried using ES6 proxies to write a wrapper over DO’s fetch()? Similar to what comlink does for WebWorkers?
  • k

    Kevin W - Itty

    04/06/2021, 2:29 AM
    No Matt, but I’ve created a base class to abstract it away
  • k

    Kevin W - Itty

    04/06/2021, 2:29 AM
    Proxies I tried for a bit and shelved... I love me some proxy hell but it’s a pain to debug in a worker
  • k

    Kevin W - Itty

    04/06/2021, 2:31 AM
    @Unsmart | Tech debt that’s the standard way to bind context within constructors... you’re resetting the method to a bound version of the same thing
  • m

    matt

    04/06/2021, 2:33 AM
    It would be nice to have the RPC style interface where you just define a method on the DO class, and you can call it on the DO stub instead of having to use fetch, especially when you are doing something where you don’t just pass through the eyeball request and would have to create one
  • k

    Kevin W - Itty

    04/06/2021, 2:35 AM
    Wouldn’t it though? I’ve gotten the DO internal code code down to be pretty readable but still a bit awkward having a router in both the worker and the DO internals
  • m

    matt

    04/06/2021, 2:38 AM
    Might have to see if I can get a demo working, I’m sure it’s possible with the Proxy class entirely in client code
  • k

    Kevin W - Itty

    04/06/2021, 2:47 AM
    Would love to see it!!
  • u

    Unsmart | Tech debt

    04/06/2021, 3:10 AM
    I've never once seen that functions you define in a class are already bound to the class?
1...495051...567Latest