Velocity: How to make a global array? - velocity

I have 3 vm files: f1.vm, f2.vm and f3.vm
in f1.vm I make the array with name PROTOCOL_VERSIONS:
#set($PROTOCOL_VERSIONS = [])
I want to add elements in PROTOCOL_VERSIONS from f2.vm file:
#set($success = $PROTOCOL_VERSIONS.add('{"major":1, "minor":0}'))
and use the PROTOCOL_VERSIONS array in the f3.vm
[
#foreach( $protocolVersion in PROTOCOL_VERSIONS )
{
"header": {
"upv": $protocolVersion,
},
} #if(!$foreach.last)
,
#end
#end
]
I tried it but unfortunately it does not initialization.
Is it possible ?

Related

Vue $watch for array of objects

I am new to Vue. We are migrating code from dojo to Vue. I was trying to add watch to an Array of objects. My data in which I have to add watch is an array of objects and Objects again can have arrays.
Sample data:
‘ItemList’: [
{
‘item’: {
‘term’: ‘1’,
‘timing’:‘A’
‘steps’: [{}], ( Array )
‘parameter’: [{}] ( Array)
…
…
almost 600 values
}
},
{
‘item’: {
‘term’: ‘2’,
‘timing’:‘B’
‘steps’: [{}],
‘parameter’: [{}]
....
....
almost 600 values
}
}
]
In old dojo the code was like this:
for (c = 0; c < itemList.length; c++) {
item=itemList[c];
var itemWatch = item.watch(function(name,oldVal,newVal) {
}
}
//Here the name gives what value of array is changed . I need that for future
//logic. we can add watch on each item.
computed:{
clonedItems: function(){
return JSON.parse(JSON.stringify(this.itemList));
}
},
watch:{
clonedItems:{
deep: true,
handler: function (val, oldVal) {
This I tried which is working fine, but to get to know what value is changed of this will be heavy computation. This array can be of 100 items and each item have 600 items where we have arrays as well.
Please guide what is the best way to achieve the similar functionality what we have.

How to add custom blocks / containers in Vuepress?

I've set up a website in VuePress and I found that it supports markdown-it's :::danger, :::tip, :::info etc to generate custom containers.
I was wondering if this could be extended in a way, to use for example :::card or :::example or whatever you want.
I found https://github.com/posva/markdown-it-custom-block, but can't find out how to implement it.
This is what've got in my config.js
markdown: {
// options for markdown-it-anchor
anchor: { permalink: false },
// options for markdown-it-toc
toc: { includeLevel: [1, 2] },
extendMarkdown: md => {
md.use(require("markdown-it-container"), "card", {
validate: function(params) {
return params.trim().match(/^card\s+(.*)$/);
},
render: function(tokens, idx) {
var m = tokens[idx].info.trim().match(/^card\s+(.*)$/);
if (tokens[idx].nesting === 1) {
// opening tag
return (
"<card><summary>" + md.utils.escapeHtml(m[1]) + "</summary>\n"
);
} else {
// closing tag
return "</card>\n";
}
}
});
}
}
Any advice is much appreciated!
The script you have will work with ::: card, in order to get it to work change
extendMarkdown: md => {...
to
config: md => {...
This took me a while to figure out. It's a version conflict - that's why it's currently not working.

Add a new element in each array of objects where array may have different length in mongodb

I have a following shema.
{
id:week
output:{
headerValues:[
{startDate:"0707",headers:"ID|week"},
{startDate:"0715",headers:"ID1|week1"},
{startDate:"0722",headers:"ID2|week2"}
]
}
}
I have to add a new field into headerValues array like this:
{
id:week
output:{
headerValues[
{startDate:"0707",headers:"ID|week",types:"used"},
{startDate:"0715",headers:"ID1|week1",types:"used"},
{startDate:"0722",headers:"ID2|week2",types:"used"}
]
}
}
I tried different approaches like this:
1)
db.CollectionName.find({}).forEach(function(data){
for(var i=0;i<data.output.headerValues.length;i++) {
db.CollectionName.update({
"_id": data._id, "output.headerValues.startDate":data.output.headerValues[i].startDate
},
{
"$set": {
"output.headerValues.$.types":"used"
}
},true,true
);
}
})
So, In this approach it is executing script and then failing. It is updating result with failed statement.
2)
Another approach I have followed using this link:
https://jira.mongodb.org/browse/SERVER-1243
db.collectionName.update({"_id":"week"},
{ "$set": { "output.headerValues.$[].types":"used" }
})
But it fails with error:
cannot use the part (headerValues of output.headerValues.$[].types) to
traverse the element ({headerValues: [ { startDate: "0707", headers:
"Id|week" } ]}) WriteError#src/mongo/shell/bulk_api.js:469:48
Bulk/mergeBatchResults#src/mongo/shell/bulk_api.js:836:49
Bulk/executeBatch#src/mongo/shell/bulk_api.js:906:13
Bulk/this.execute#src/mongo/shell/bulk_api.js:1150:21
DBCollection.prototype.updateOne#src/mongo/shell/crud_api.js:550:17
#(shell):1:1
I have searched with many different ways which can update different arrays object by adding new field to each object but no success. Can anybody please suggest that what am I doing wrong?
Your query is {"_id" : "week"} but in your data id field is week
So you can change {"_id" : "week"} to {"id" : "week"} and also update your mongodb latest version
db.collectionName.update({"id":"week"},
{ "$set": { "output.headerValues.$[].types":"used" }
})

How to populate empty array with a method in Vue

I'm trying to populate an empty array with a declared array variable in a computed function. I tried this but with no luck:
data: {
hashtags: []
},
computed: {
filteredHashtags () {
var defaultHashtags = [ '#hr', '#acc', '#sales' ];
var fHashtags =
_.chain( messages )
.pluck( 'hashtags' )
.flatten()
.map(
function ( tag ) {
return tag && tag.trim() ? '#' + tag : null; })
.filter( Boolean )
.value();
fHashtags = _.union( fHashtags, defaultHashtags );
return data.hashtags = fHashtags;
}
}
also, is there a better method to approach this?
A computed property isn't really a good use case for this, because the computed value has to be referenced in order for it to be called. Instead, just make it a method and call it the method when your Vue is created.
data: {
hashtags: []
},
methods: {
filterHashtags() {
// commented out stuff
// set the data property with the filtered values
this.hashtags = fHashtags;
}
},
created(){
this.filterHashtags();
}

Ramda `evolve` nested object

I have a list similar to this:
var list = [
{
stack: [
{
file: 'abc'
}
]
},
{
stack: [
{
file: 'abc'
},
{
file: 'abc'
}
]
}
];
I want to change every file name with e.g 'def'. How to do that by using ramda ?
I tried things like:
var trans = {
file: replace('abc', 'def')
};
var f = R.evolve(trans)
var f2 = R.map(f)
R.map(f2, list)
But it doesn't work. I need to include stack field in solution somehow.
Well, it's not pretty, but I think this will do it:
R.map(R.over(
R.lensProp('stack'),
R.map(R.over(R.lensProp('file'), R.replace('abc', 'def')))
))(list)
You could probably also use an evolve inside, but lenses are pretty powerful, and more generally useful.