How do I export data from component actions?

This topic was automatically generated from Slack. You can find the original thread here.

Nghia Nguyen : quick question on the updated components action replacement: is it supposed to not save information in the steps.{step-name-here}.{variable-name-here} via the use of this.{variable-name-here} anymore? I’m testing out the replacement to the old legacy actions and it seems like the this.{variable-name-here} = ... doesn’t store the info anymore to access at a downstream step. Also, ignore the false flag promisify warnings in this screenshot:

Pravin Savkar : Great question! And you are correct – this refers to component bindings, so this.{variable-name-here} does not export data from a component.

Currently, the only option to export data is to return it. However, we are actively working on enhancements that will also enable exporting data to custom keys (similar to this.{variable-name-here}). We can let you know when that feature is ready to test.

Can you work around this limitation for the time being or are you blocked?

Nghia Nguyen : I mean I can always checkpoint data if that’s allowed

Nghia Nguyen : just keeping in mind workflow downstream code that i’ll have to modify once i swap the component in

Pravin Savkar : Checkpointing works differently with components as well, so I don’t think that will work. Let me check with the team – I may be able share some details on working with custom exports (although that feature is not final so is subject to change).

Nghia Nguyen : Ah okay. I guess I’ll just build an object along the way and return it. Good to know about the limitations here.

Pravin Savkar : Thanks for the flexibility ! The feature is currently in beta and we’re actively working on evolving it (I can update the docs if that wasn’t clear)! And please let us know if you have any other feedback on components as you use them!

Pravin Savkar : Here’s an example that demonstrates how to export data to a custom key from a component. Please note: this feature is experimental and is subject to change.

module.exports = {
  name: "$.export() Example",
  description: "$.export() example -- note: this feature is experimental and is subject to change",
  key: "export_example",
  version: "0.0.5",
  type: "action",
  props: {},
  async run({$}) {
    // NOTE: $.export() is experimental and is subject to change 
    $.export("foo","This export will be assigned to the key `foo`.") 
    return `This is the return value.`
  },
}

To use the feature, first add {$} to the run signature:

async run({$}) {
...
} 

Then, export data using $.export("KEY-NAME", VALUE).

Nghia Nguyen : ah thanks for the info Pravin, but I don’t think I can put experimental features that can change/break on a whim into these workflows

Pravin Savkar : No problem! I just wanted to provide you with the option – we’ll let you know when it’s final.