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

    kenton

    02/09/2021, 12:32 AM
    I think we could make it possible to use a class as your main worker entrypoint (not DO), and then
    env
    would be passed to the constructor instead of each handler call
  • j

    jed

    02/09/2021, 12:32 AM
    yeah, aligning those APIs would make it easier to onboard folks.
  • j

    jed

    02/09/2021, 12:32 AM
    (i think)
  • k

    kenton

    02/09/2021, 12:33 AM
    well, at one point that is what I proposed, but a lot of feedback suggested people were put off by having to declare a class rather than a function. But in the case of Durable Objects specifically, classes make more sense, since objects are instances of classes in OOP
  • j

    jed

    02/09/2021, 12:33 AM
    i guess it comes down to whether you see DOs as
    stateful workers
    or
    workerful states
    , haha.
  • j

    jed

    02/09/2021, 12:35 AM
    once you have more than one method/function, classes definitely make more sense.
  • k

    kenton

    02/09/2021, 12:35 AM
    also, outside of durable objects, the lifetime of any particular instance of this class, and which requests get routed to it vs. other instances, would be totally arbitrary
  • k

    kenton

    02/09/2021, 12:36 AM
    which is fine for people who get it, but maybe confusing for some
  • k

    kenton

    02/09/2021, 12:37 AM
    for non-durable-objects, we really want people to think of each request as being handled by a new worker independent of any other... global variables currently break that abstraction, but we might change that someday
  • j

    jed

    02/09/2021, 12:38 AM
    yeah, it's hard to anticipate when your potential users are so broad.
  • j

    jed

    02/09/2021, 12:38 AM
    lot of folks used to server stuff, but also very accessible to front-enders.
  • j

    jed

    02/09/2021, 12:38 AM
    i think react has taught a lot of folks about immutability
  • j

    jed

    02/09/2021, 12:39 AM
    so i think closures are kinda natural in that sense.
  • k

    kenton

    02/09/2021, 12:39 AM
    I might go ahead and make it possible to use a class to implement a regular (non-DO) worker, but it would be optional and probably not what we show in beginner documentation
  • k

    kenton

    02/09/2021, 12:40 AM
    Out of curiosity do you have an FP background? 🙂
  • j

    jed

    02/09/2021, 12:40 AM
    i'm not sure... i like FP in JS a lot but am not dogmatic about it.
  • j

    jed

    02/09/2021, 12:43 AM
    basically front-end frameworks seem to be moving towards FP, so seems maybe a good wave to ride in terms of API design.
  • j

    jed

    02/09/2021, 12:43 AM
    users know that a view is rerendered when its state changes, so makes sense that a worker would be redeployed when its env changes, for example.
  • j

    jed

    02/09/2021, 12:43 AM
    anyway, sorry to get a bit academic.
  • j

    jed

    02/09/2021, 12:44 AM
    workers are awesome. and to me DO are to server what react was to client.
  • j

    jed

    02/09/2021, 12:44 AM
    rethinking how things are organized.
  • j

    jed

    02/09/2021, 12:44 AM
    ie, before react you had CSS, HTML, and JS in their own silos.
  • j

    jed

    02/09/2021, 12:45 AM
    react said let's colocate those per component.
  • j

    jed

    02/09/2021, 12:45 AM
    before DO, you had compute, network, and storage in their own silos (lambda, API Gateway, dynamo).
  • j

    jed

    02/09/2021, 12:46 AM
    DO said let's colocate these per instance.
  • j

    jed

    02/09/2021, 12:46 AM
    it's really nice.
  • k

    kenton

    02/09/2021, 12:46 AM
    oh I just realized what you really meant with the
    state =>
    closure earlier... it works well as long as there is only one handler (
    fetch()
    ), but I've been thinking in terms of multiple handlers all along.
  • j

    jed

    02/09/2021, 12:47 AM
    right
  • k

    kenton

    02/09/2021, 12:47 AM
    we actually have three types currently,
    fetch()
    ,
    scheduled()
    , and
    trace()
    (which is not available publicly yet)
  • k

    kenton

    02/09/2021, 12:47 AM
    and plan to add others
1...141516...567Latest