Closed foegit closed 1 year ago
Hi @foegit Thanks for reporting
It will be fixed within in next release.
You can add the following snippet for Javascript files.
{
"Require Class Cache": {
"prefix": "reqCache",
"body": [
"const Cache = require('dw/system/Cache');"
],
"description": "Require Class Cache"
},
"Require Class CacheMgr": {
"prefix": "reqCacheMgr",
"body": [
"const CacheMgr = require('dw/system/CacheMgr');"
],
"description": "Require Class CacheMgr"
},
}
Please note I use const instead of var. I noticed before 2019 const was used instead of var. I don't know why but will appreciate to know :) I always use const except in ISML iscript due to hoisting.
Regards
Hi @aduponchel
const
in not recommend to use since it has non standard behavior in comparison to ES6. For instance it has lexical scope instead of block scope. Try to guess result
value after next code:
var result = ''
if (true) {
const test = 'second'
}
result = test
or this code also will work
var result = ''
const test
if (true) {
test = 'second'
}
result = test
or this example:
const product = getProduct(/*...*/)
if (true) {
// SFCC will throw error here while ES6 just create new block scoped variable
const product = getProduct(/*...*/)
}
none of this error can be catched by IDE or eslint since tools counts on ES6 standart.
Please note: Salesforce avoid usage of const
in SFRA (along with let
and empty
)
fixed in 1.4.34
req snippet doesn't work for CacheMgr (https://documentation.b2c.commercecloud.salesforce.com/DOC2/topic/com.demandware.dochelp/DWAPI/scriptapi/html/api/class_dw_system_CacheMgr.html)
To Reproduce
reqCache
Expected behavior The extension suggests a snippet to be inserted
var CacheMgr = require('dw/system/CacheMgr');
Screenshots
Desktop (please complete the following information):