バージョン0.19の新機能
コンテキストストアAPIは、 コンテキストデータをどこに格納するか設定する方法を提供します。
デフォルトでは、Node-REDは Memoryストア のAPIを使用します。 また、Fileストア も提供しています。
コンテキストストアをカスタマイズするには、ストアモジュールAPI を実装するモジュールを作成しなければなりません。
settings.js内の contextStorage
プロパティは、コンテキストストレージの設定に使用されます。
これはオブジェクトであり、1つ以上の名前を持ったコンテキストストア設定です。
contextStorage: {
default: {
module:"memory",
config: {
customOption: 'value'
}
}
}
それぞれのコンテキストストア設定は、
module
プロパティと config
プロパティの2つで構成されます。
module
プロパティは、使用するコンテキストストアプラグインを特定します。
これは、ビルトインモジュールの名前(現時点では memory
または localfilesystem
)であるか、または
require
でロードされたモジュールであるべきです。
contextStorage: {
default: {
module:"memory",
},
custom: {
module:require("my-custom-store")
}
}
config
プロパティはオブジェクトであり、
カスタムオプションを提供するためのモジュールに渡されます。
カスタムプラグインのモジュールは、単一のコンストラクタ関数をexportしなければなりません。
この関数はプラグインの新しいインスタンスがrequiredされた時に呼び出されます。
そして、関数にはそのインスタンスの config
プロパティの値が渡されます。
これは、ランタイムが同じストアプラグインの複数のインスタンスを保持することを許容することになり、それぞれに自身の設定を保持します。
var ContextStore = function(config) {
this.config = config;
}
ContextStore.prototype.open = function() { ... }
module.exports = function(config){
return new ContextStore(config);
};
コンストラクタにより返されるオブジェクトは、 こちら に記載されているすべての関数を実装しなければなりません。
Node-RED: Low-code programming for event-driven applications.
Copyright OpenJS Foundation and Node-RED contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
The OpenJS Foundation | Terms of Use | Privacy Policy | OpenJS Foundation Bylaws | Trademark Policy | Trademark List | Cookie Policy