add randomUUID expression and scripting functions#94
Conversation
|
Ooh, I like it. I actually had an idea written down somewhere about adding a UUID function. Granted, this is contrived, but I wonder if it's worth baking some flexibility in - e.g. make the function From the other angle - is returning a direct UUID object preferred? Should the expression at least return a string, and maybe we also add a |
|
I can dig
My use case is for the string representation, but in my testing returning the UUID object seemed to give me the expected results everywhere I tried it (Perspective bindings, Vision bindings, expression tags) 🤷🏻♂️. My thinking was that letting it get implicitly converted to a string was fine. You definitely know more than me about what's kosher for expression functions though, I don't have a strong preference. |
|
Okay, cool. I think I'm convinced it's fine to hand back a 'true' UUID, probably more correct than anything else. Do you mind changing the expression and scripting functions to |
|
Can do, want `uuidv4` or `uuid4`?
Also, what do you think about the current tests? They're kinda dumb right
now, they only check that the function returns a different value when
called twice.
Maybe a test for string length of 36 would be good?
…On Tue, Sep 10, 2024 at 2:21 PM Paul Griffith ***@***.***> wrote:
Okay, cool. I think I'm convinced it's fine to hand back a 'true' UUID,
probably more correct than anything else. Do you mind changing the
expression and scripting functions to uuid4? That leaves us runway to
implement our uuidv7, theoretically, which would otherwise be a bit
confusing with "randomUUID" already in place.
—
Reply to this email directly, view it on GitHub
<#94 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AN3FNSV4QKGFFOLFMCKWL6TZV42BPAVCNFSM6AAAAABNVHCDC2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNBRG4YDOMJYGA>
.
You are receiving this because you authored the thread.Message ID:
<IgnitionModuleDevelopmentCommunity/ignition-extensions/pull/94/c2341707180
@github.com>
|
|
Let's go On the tests: Meh, there's not really anything to test (which I think is a good thing!) - we're just deferring to the JDK implementation, and there's no way to insert a testable RNG or anything into that, which I also think is good. I'd honestly probably just test:
I don't think there's anything else that would really add value. |
Adds both a
randomUUID()expression function and asystem.util.randomUUID()scripting function, that simply return the result ofjava.util.UUID.randomUUID().My main use case is the expression function in Perspective.
When dealing with messaging between embedded views and their parents, it is useful to give the parent a unique identifier and pass it to the child views. When the child sends messages, it includes the
uuidin the payload so the parent can validate it is the intended target. The uuid doesn't need to be persistent and can simply be assigned when the page loads.