Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Using variables in actions #9

Closed
AlexGustafsson opened this issue Nov 20, 2018 · 2 comments
Closed

Using variables in actions #9

AlexGustafsson opened this issue Nov 20, 2018 · 2 comments

Comments

@AlexGustafsson
Copy link

AlexGustafsson commented Nov 20, 2018

Inspired by this, I'm currently working on a JavaScript to iOS shortcuts transpiler. I've gotten most of the parsing done and I'm now working on the transpiler portion of the project. My intention is to utilize this library since I really appreciate the effort you have put in it and what shape it's taking.

One question comes to mind however, how are variables handled? Most actions on iOS are able to work with either magic variables or actual variables as parameters (not input). How are these or how will these be available through this package?

@xAlien95
Copy link
Contributor

At the moment, you can only use magic variables (action outputs) in strings and it's done via JS template strings and the withVariables tag function: take a look to Minimal Example to see how it works.

// We'll use this later to reference the output of a calculation
let calcId;

// Define our list of actions
const actions = [
  number({
    number: 42,
  }),
  calculate({
    operand: 3,
    operation: '/',
  }, (id) => {
    // We'll use this again in a moment
    calcId = id;
  }),
  showResult({
    /**
     * We can use the result of the calculation in this Shortcuts's input
     * by passing the string to the 'withVariables' tag function
     */
    text: withVariables`Total is ${calcId}!`,
  }),
];

Pull request #8 adds support for actual variables too, but it's not currently merged.
Future releases may slightly change how variables are handled.

@joshfarrant
Copy link
Owner

Exactly right, thanks @xAlien95.

We’re still pre v1, and there were a few things that I’d not considered when designing the current implementation of variables. Because of this, things might well change in the future. There’s a bit more discussion around this topic in #4.

Sent with GitHawk

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants