Git Product home page Git Product logo

Comments (3)

joshfarrant avatar joshfarrant commented on May 18, 2024

It's really an interesting idea! The current method for building a Shortcut (as an array of functions) is by no means the way it has to be done forever, so it's interesting to see options for other ways it could be done. This isn't something I'd considered before now, but it's very cool to see - Thanks so much for putting it forward!

To be honest I've been thinking about something similar, but using chained function calls rather than the builder pattern you suggested.

At this point in time, even a basic shortcut will look horribly messy in this format. You'll end up with either this:

comment({ text: 'Hello World' })(number({ number: 42 })(calculate({ operand: 3, operation: '/' }, id => (calcId = id))(showResult({ text: withVariables`Total is ${calcId}!` }))));

Or this (which is only slightly more readable).

comment({ text: 'Hello World' })(
  number({ number: 42 })(
    calculate({ operand: 3, operation: '/' }, id => (calcId = id))(
      showResult({ text: withVariables`Total is ${calcId}!` })
    )
  )
);

Hopefully we can all agree that these are both awful!

However, with the magic of the Pipeline Operator (Currently a Stage 1 proposal), we could end up with something like this:

shortcuts
  |> comment({ text: 'Hello World' })
  |> number({ number: 42 })
  |> calculate({ operand: 3, operation: '/' }, id => (calcId = id))
  |> showResult({ text: withVariables`Total is ${calcId}!` })

Granted, I've not looked into it in enough detail to know exactly how it would be implemented or used, but it's something that's been in the back of my mind that I thought I'd share. At this point it seems very likely that the Pipeline Operator will make it's way into JS (and then hopefully TypeScript), so it's another thing to think about!

from shortcuts-js.

Archez avatar Archez commented on May 18, 2024

Since Shortcuts can also take a tree path, instead of linear, (e.g. if/else, chooseMenu), I can foresee a chained/builder approach not being an elegant solution.

Secondly, one thing to keep in mind is that import questions target their corresponding action by index, so the array approach lends some credibility. However, I have not checked what index is used for a import question on an action within a branched path.

from shortcuts-js.

joshfarrant avatar joshfarrant commented on May 18, 2024

Good point. This is something I was thinking about before I implemented if/else and chooseFromMenu, so it made a bit more sense then. The addition of those actions does make it a bit more complicated.

from shortcuts-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.