Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(script): add dynamic switch command to example #1121

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/script-example/dynamicSwitch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @description: Simulated dynamic switch command
* @param {string | object} value - Payload
* @param {string} msgType - Message type, value is 'received' or 'publish'
* @param {number} index - Index of the message, valid only when script is used in the publish message and timed message is enabled
* @return {object} - Return two commands alternately, { "command": "on" } or { "command": "off" }
*/
function handlePayload(value, msgType, index) {
let _value = value
if (typeof value === 'string') {
_value = JSON.parse(value)
}
if (index % 2 === 0) {
_value.command = 'on'
} else {
_value.command = 'off'
}
return JSON.stringify(_value, null, 2)
}

execute(handlePayload)
2 changes: 1 addition & 1 deletion src/views/script/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default class Script extends Vue {
* @description: default script
* @param {any} value - Payload
* @param {string} msgType - Message type, value is 'received' or 'publish'
* @param {number} index - Index of the message, vaild only when script is used in the publish message and timed message is enabled
* @param {number} index - Index of the message, valid only when script is used in the publish message and timed message is enabled
* @return {any} - Payload after script processing
*/
function handlePayload(value, msgType, index) {
Expand Down