程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2023-05(5)

nodeRed 源码分析8- runtime nodes模块分析

发布于2021-03-07 22:02     阅读(1128)     评论(0)     点赞(4)     收藏(4)


功能概述

提供运行时与节点相关的接口,如节点注册、流程增删改查、节点模块处理、上下文等。

所依赖的三方库

  • when
  • path
  • fs
  • clone
  • util

文件域变量

  • @node-red/registry
    • 为runtime提供节点注册、响应、发现及管理功能
  • credentials
    • 封装credentials相关操作
  • context
    • 提供上下文环境,可定义变量、保存等
  • Node
    • 为所有新建立的节点提供初始化

API

FunctionDescription
// Lifecycle----
init初始化函数,调用涉及的几个模块的init方法
load加载依赖模块
// Node registry----
createNode调用Node模块创建一个节点,并配置credentials
getNode调用flow模块获取节点
eachNode调用flow模块遍历所有节点,可传入回调函数
getContext调用context模块获取上下文
installModule安装一个模块
uninstallModule删除一个模块
enableNode启用一个模块
disableNode禁用一个模块
// Node type registry----
registerType调用registry模块注册节点
getType调用registry模块获取节点类型
getNodeInfo调用registry模块获取节点信息
getNodeList调用registry模块获得已安装的node modules
getModuleInfo调用registry模块获得node module信息
getNodeConfigs调用registry模块获取所有节点的html内容
getNodeConfig调用registry模块获取某个node的html内容
getNodeIconPath调用registry模块获取某个node的图标
getNodeIcons调用registry模块获取所有节点的图标
getNodeExampleFlows调用registry模块获取示例流程
getNodeExampleFlowPath调用registry模块获取示例流程目录
clearRegistry调用registry模块清除registry模块内容
cleanModuleList调用registry模块清除模块列表
// Flow handling----
loadFlows调用flow模块完成流程加载
startFlows调用flow模块完成流程启动
stopFlows调用flow模块完成流程结束
setFlows调用flow模块完成全部流程的设置
getFlows调用flow模块返回所有流程
addFlow调用flow模块返回增加流程
getFlow调用flow模块返回获取流程
updateFlow调用flow模块更新获取流程
removeFlow调用flow模块更新删除流程
// Credentials----
addCredentials调用credentials模块增加凭证
getCredentials调用credentials模块获取凭证
deleteCredentials调用credentials模块删除凭证
getCredentialDefinition调用credentials模块获取凭证定义
setCredentialSecret调用credentials模块设置凭证密码
clearCredentials调用credentials模块清除凭证
exportCredentials调用credentials模块导出凭证
getCredentialKeyType调用credentials模块获取凭证类型
// Contexts----
loadContextsPlugin调用context模块加载上下文保存插件
closeContextsPlugin调用context模块关闭上下文保存插件
listContextStores调用context模块罗列上下文保存插件

涉及文件

  1. packages\node_modules@node-red\runtime\lib\nodes\index.js

代码分析

参与流程

other index.js@nodes@lib@runtime credentials.js@nodes@lib@runtime index.js@flows@lib@runtime index.js@lib@registry context.js@nodes@lib@runtime init() 1 init() 2 init() 3 init() 4 init() 5 other index.js@nodes@lib@runtime credentials.js@nodes@lib@runtime index.js@flows@lib@runtime index.js@lib@registry context.js@nodes@lib@runtime 初始化
other index.js@nodes@lib@runtime index.js@lib@registry registry.js@lib@registry index.js@flows@lib@runtime Node.js@nodes@lib@runtime load() 1 load() 2 registerType() 3 registerType() 4 registerNodeConstructor() 5 loadFlows() 6 load() 7 startFlows() 8 startFlows() 9 createNode() 10 Node() 11 other index.js@nodes@lib@runtime index.js@lib@registry registry.js@lib@registry index.js@flows@lib@runtime Node.js@nodes@lib@runtime start, 加载流、节点等
other index.js@nodes@lib@runtime index.js@lib@registry installModule() 1 installModule() 2 uninstallModule() 3 uninstallModule() 4 other index.js@nodes@lib@runtime index.js@lib@registry 安装/卸载模块
other index.js@nodes@lib@runtime index.js@lib@registry enableNode() 1 enableNode() 2 reportNodeStateChange() 3 disableNode() 4 disableNode() 5 reportNodeStateChange() 6 other index.js@nodes@lib@runtime index.js@lib@registry 禁用/使用节点

例子

  1. 使用html参数创建节点
function MQTTBrokerNode(n) {
    RED.nodes.createNode(this,n);
    
}
  1. 使用html参数创建节点
function MQTTBrokerNode(n) {
    
    this.brokerConn = RED.nodes.getNode(this.broker);//根据ID从已注册的节点中找
    
}

原文链接:https://blog.csdn.net/lxmuyu/article/details/114382812




所属网站分类: 技术文章 > 博客

作者:前端霸主

链接:http://www.qianduanheidong.com/blog/article/33570/0ca6c81129368fd5bdff/

来源:前端黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

4 0
收藏该文
已收藏

评论内容:(最多支持255个字符)