The bug source code is here.
Let's say I'm looping over an array in Meteor using an ordinary {{#each}} loop. Each array element is a string, and I output the string every step using {{this}}. So far so good! If I use a handlebars helper to check typeof for this I'll get string. Sweet! Everything is as it should be.
But if I add an {{#if something }}-helper inside the {{#each}} (the something just returns true and thus keeps going and outputs {{this}}) the string will still look good in the HTML, but it is now an object in the typeof check!
This is super-annoying as all the (typeof someVarINeedToTest === 'string') my code might depend on now will return false.
Am I doing something wrong?
Or is this an actual bug?
If so: is it a Meteor-specific or Handlebars-specific bug?
Thanks!
Oh: the source link again. Just pull and run meteor and look in your browser console.
This is because the this variable is supposed to always be an object in JavaScript so when someFunction.apply(someContext); is called in by handlebars, JavaScript turns someContext into an object no matter what it started as. See an example here: http://jsfiddle.net/SyKSE/1/
(In this case, someFunction represents the part of your template that's within the {{#if}} statement.)
A simple (albeit ugly) workaround would be to just always pass your data in as an object, so
['this', 'is', 'an', 'array', 'that', 'we\'re', 'looping', 'through'];
becomes:
[{val: 'this'}, {val: 'is'}, {val: 'an'}, {val: 'array'}, {val: 'that'}, {val: 'we\'re'}, {val: 'looping'}, {val: 'through'}];
And then you'd change your template to look at val instead of this
Related
I'm converting some working JavaScript code to Flow. I have a variable IMAGES which is created but not immediately assigned any value. Later on it becomes an array of HTML elements.
Why is this code wrong?
let IMAGES Array<HTMLElement>;
// Later on within an init function:
IMAGES = Array.from(document.querySelectorAll(`.${someImagesClass}`));
The Flow error I get is:
Parsing error: Unexpected token, expected ";"
All I was missing was the :
let IMAGES: Array<HTMLElement>;
There is no generic-syntax and no need to "publish" a variable in JavaScript! Just merge both:
// Later on within an init function:
let IMAGES = Array.from(document.querySelectorAll(`.${someImagesClass}`));
How can we access the url's query parameters in a Clack environment ?
It looks like they are in a clack *request* object, named query-string, but I don't know how to access them: clack is not documented and this doc isn't clear on that.
BTW, how to explore the *request* in slime's debugger, while I'm on a break for instance ? it only prints as "CLACK:REQUEST".
I see nothing in Lucerne's doc or code, and it's a shame because I like its with-params macro.
update: don't search more, this macro works very well !
Caveman has something but the common case isn't that clear to me (some find like me it is a bit cumbersome (and I'm trying out Lucerne)).
In Ningle, I can do (lack.request:request-query-parameters ningle:*request*) to get association list with all query parameters. May be it will work for you.
To inspect request in a frame, just hit "i" when cursor on a frame and enter something like ningle:*request*. I see the request like that:
#<LACK.REQUEST:REQUEST {100B2EDB73}>
--------------------
The object is a STRUCTURE-OBJECT of type LACK.REQUEST:REQUEST.
ENV: (:RAW-BODY #<FLEXI-STREAMS::VECTOR-INPUT-STREAM {100B2ED2D3}> :REQUEST-METHOD :GET :SCRIPT-NAME "" :SERVER-NAME "ws-dashb$
METHOD: :GET
SCRIPT-NAME: ""
PATH-INFO: "/some-path"
And can dive into each slot's value.
Probably it depends on optimization declarations. If does not work, try to enter (declaim (optimize (debug 3))) before loading your application.
I have simple task to do but unable to find the exact solutions for this.I have saved a file as abc.xml in MarkLogic.How can i rename the file as some example.xml using XQuery?
Code which I tried:
xquery version "1.0-ml";
xdmp:document-rename ("/aaa.xml","/final.xml");
This is showing an error.
There is no way, that I know of, to change the document URI of an existing document. The only way I can think of is to create a new document with the same content and the new URI, and delete the existing one, in the same transaction.
Where it gets tricky is to make sure to preserve the ownership, the permissions, all the properties, the property document, make sure that the old URI is not used anywhere to link to the existing document, etc.
But usually, the document URI is never really used. You should first considering whether you really need to rename the document, and why.
(Note that saying "this is showing an error" is rarely useful on SO or on mailing lists, if you do not show what the error is.)
Florent is correct, a true 'rename' is not possible, or perhaps not even meaningful. ( analogy - rename a file from one disk to another )
"Move" however is meaningful (copy then delete in a transaction).
Defining "Move" is use case dependent - i.e. what metatdata also needs to 'move' ? permissions? collections ? document properties ? inherited permissions ?
xmlsh (http://www.xmlsh.org) implements a 'rename' (http://www.xmlsh.org/MarkLogicRename) command for the marklogic extension which is really a 'move', with the implemenation borrowed from postings on markmail (http://markmail.org/)
The implementation is the following XQuery - it doesnt do everything you might want and it might do more then you want. YMMV
https://github.com/DALDEI/xmlsh/blob/master/extensions/marklogic/src/org/xmlsh/marklogic/resources/rename.xquery
( it was also written long ago - it is likely to benefit from improvement )
I have working example this works for me.
xquery version "1.0-ml";
declare function local:document-rename(
$old-uri as xs:string, $new-uri as xs:string)
as empty-sequence()
{
xdmp:document-delete($old-uri),
let $permissions := xdmp:document-get-permissions($old-uri)
let $collections := xdmp:document-get-collections($old-uri)
return xdmp:document-insert(
$new-uri, doc($old-uri),
if ($permissions) then $permissions
else xdmp:default-permissions(),
if ($collections) then $collections
else xdmp:default-collections(),
xdmp:document-get-quality($old-uri)
)
,
let $prop-ns := namespace-uri(<prop:properties/>)
let $properties :=
xdmp:document-properties($old-uri)/node()
[ namespace-uri(.) ne $prop-ns ]
return xdmp:document-set-properties($new-uri, $properties)
};
(: function call :)
local:document-rename ("/opt/backup/x.xml","y.xml");
MarkLogic has a tutorial up addressing file renaming (moving):
https://developer.marklogic.com/recipe/move-a-document/
Importantly, it uses the function xdmp:lock-for-update() to prevent modifications to the source file while it is being copied to the target location.
Also, if you are doing a batch renaming you'll want to make sure that each file URI you rename corresponds to a document in the database or you'll get runtime errors.
Given the following Meteor code helper from the websites "Try Meteor" tutorial:
// Add to Template.body.helpers
incompleteCount: function () {
return Tasks.find({checked: {$ne: true}}).count();
}
I get pretty much everything about this code except for this arbitrary looking $ne thing. I've seen this before with Meteor examples and I don't get it: What does $ne represent? Where did $ne come from?
$ne means not equal to.
It is preferable to use this instead of {checked: false} since it also includes the ones where the checked attribute isn't in the document {} and the case where {checked: null} as both of these are cases where checked isn't equal to true & are also not false.
This way if you have a fresh document without any attributes it would also be a result of the query.
In Smarty, I know you can declare a string:
{$somevar|default:'some string'}
or even an array:
{$somevar|default:array('someval')}
How do you/Is it possible to set an associative array as a default value? as this doesn't seem to work:
{$somevar|default:array('default'=>array('subkey'=>'subval'))}
I just tried:
{$somevar|default:array('key'=>'val')}
It's the '=>' smarty doesn't like
I know its probably not the solution you're looking for, but you can always just use the {php} feature. However, I will try a few things and see if I can work the format out.
Just out of interest, why are you trying to do this in the tpl file and not in the calling PHP script?
Edit
From takeing a read, it doesn't seem like it is possible. However, there is a "set" plugin which allows it, see here (bottom example).