Skip to content

Documentation issue #406

@mike-s123

Description

@mike-s123

Placed here at direction of @hardillb.

Documentation for context stores is incorrect. It says

// Get value - sync
var myCount = flow.get("count", storeName);

// Get value - async
flow.get("count", storeName, function(err, myCount) { ... });

// Set value - sync
flow.set("count", 123, storeName);

// Set value - async
flow.set("count", 123, storeName, function(err) { ... })

... which fails because storeName actually has to be provided as a string. The key count is shown in quotes, storeName isn't. This is inconsistent. Without quotes also around storeName, one is lead to believe that it's simply the identifier name as defined in contextStorage:.

Expected Behavior

storeName should be enclosed in quotes to indicate that a string is expected.

Comments

Re the response found here.

In the example, storeName is not a variable. A variable must be created, e.g. let storeName = 'file'. Nowhere else in the documentation does storeName appear. When creating context storage, the template is:

contextStorage: {
   default: "memoryOnly",
   memoryOnly: { module: 'memory' },
   file: { module: 'localfilesystem' }
}

what are memoryOnly and file? They are identifier names, not variables or strings, and it would be perfectly reasonable to refer to them as storeNames. In addition, the claim that "The reason it's shown as a variable is that storeName will very much depend on what context stores the Node-RED instance has enabled" applies equally to the key (count is also not intrinsic), which is shown as a string literal. The example is inconsistent and ambiguous.

Appropriate, internally consistent, and unambiguous would be either:

let keyName = "count";
let storeName = "file";
// Get value - sync
let myCount = flow.get(keyName, storeName);

or

// Get value - sync
let myCount = flow.get("count", "file");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions