Comments (3)
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.
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.
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)
- Color and glyphs are not available HOT 3
- Add Bear actions
- Is it possible to port the "shortcuts" app to Android๏ผ Parsing the file format and Implement the action. HOT 1
- Speak Text HOT 3
- Better Contribution flow
- Add Replace Text Action
- Add Change Case Action
- Error in REDME
- Hacktoberfest Opt-in HOT 1
- Shortcut parser needs to support both binary bplist and xml plist
- Creating ShortCut URL in iCloud
- How do I get started? HOT 1
- Add getFile Action
- Looking for new maintainers ๐ HOT 21
- Json shortcut
- Getting Shortcuts to "tap" items on the screen HOT 1
- Chrome warns about usage of navigator.userAgent, navigator.appVersion, and navigator.platform HOT 1
- Shortcut for iOS setting?
- Jump/Go to Bottom of Page Request
- github
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shortcuts-js.