Skip to content

Commit

Permalink
Always fetch the fresh variable data when populating
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Boberg <[email protected]>
  • Loading branch information
axelboberg committed Apr 21, 2024
1 parent b8a9a0c commit 39b8bf4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 6 additions & 3 deletions api/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,10 @@ function deepClone (obj) {
*
* @param { any } item
* @param { any } type
* @param { any } values
* @returns { any } The item with modified property values
*/
function populateVariablesMutable (item, type) {
function populateVariablesMutable (item, type, values) {
if (!item.data) {
item.data = {}
}
Expand All @@ -239,7 +240,7 @@ function populateVariablesMutable (item, type) {
const currentValue = objectPath.get(item.data, key)

if (currentValue != null) {
objectPath.set(item.data, key, JSON.parse(variables.substituteInString(JSON.stringify(currentValue))))
objectPath.set(item.data, key, JSON.parse(variables.substituteInString(JSON.stringify(currentValue), values)))
}
}

Expand All @@ -263,7 +264,9 @@ async function playItem (id) {
}

const type = await types.getType(item.type)
const clone = populateVariablesMutable(deepClone(item), type)
const vars = await variables.getAllVariables()
const clone = populateVariablesMutable(deepClone(item), type, vars)

const delay = parseInt(clone?.data?.delay)

if (delay && !Number.isNaN(delay)) {
Expand Down
9 changes: 9 additions & 0 deletions api/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ function getVariable (key) {
}
exports.getVariable = getVariable

/**
* Get all variables' values
* @returns { Promise.<any> }
*/
async function getAllVariables () {
return state.get('variables')
}
exports.getAllVariables = getAllVariables

/**
* Substitute variables for their
* values in a string
Expand Down

0 comments on commit 39b8bf4

Please sign in to comment.