Watch for element visibility change in angulardart - scope

I have the same exact question that has already been posted for angularjs (Angular - Watch for ngShow/ngHide Changes in Ancestors that Affect Child DOM Element's Visibility) except in my case we are using angulardart. I cannot seem to watch a function in angulardart. When I try to, I get an error from the expression parser stating that "{" is unexpected. Is there a better way to do this in angulardart? If not, how can I watch a function similar to angularjs?
I've tried the following code with no success:
scope.watch("() { return _element.hidden; }", (value, _) {
print(value);
});
Parser Error: Unexpected token ) at column 2 in [() { return _element.hidden; }]
scope.watch("(scope) { return _element.hidden; }", (value, _) {
print(value);
});
Parser Error: '{' is an unexpected token at column 9 in [(scope) { return _element.hidden; }]
We are using angular.dart 1.1.2

You could use MutationObserver, it notifies about DOM changes. See for example In Dart why the code below (about MutationObserver) dose not work? (there should be more examples on SO)

Related

Repeatable attribute tags in markojs

I want a custom tag for tabs that will give me the possibility to write following code
app-tabset#my-tab
#tab title="first"
p -- content of first tab
#tab title="second"
p -- content of second tab
but I can't get it to consume repeated attribute, hence in app-tabset.marko
onMount() {
console.log('incoming tabs', this.input.tab)
// expected an array but only object of second tab
// "{title="second", renderBody: function}"
}
Reading the docs in repeated attribute tags i add a marko-tag.json
{
"<tab>": {
"is-repeated": true
}
}
This compiles fine but when loading the page i get
Render async fragment error (lasso-slot:head).
Exception: Error: Unable to load tag ([C:\projects\marko\src\components → C:\projects\marko\src\components\app-tabset\marko-tag.json]):
Error: Error while applying option of "<tab>".
Cause: Error: Unsupported properties of [is-repeated]
In case you haven't found a solution yet, try this in your marko-tag.json file
{
"#tabs <tab>[]": {
"#title": "string"
}
}

How to add multiline painless code in nodejs

So in my js-code I have this line:
var _script = {
_script: {
script: {
lang: 'painless',
source: `
"""
if(1>2){
params._source.id;
}
else{
params._source.id;
}
"""
`
},
type: 'string',
order: params._source.id
}
}
This will fail. I see in the log this error message:
,\"reason\":\"unexpected token ['\\\"\\\\n if(1>2){\\\\n params._source.id;\\\\n }\\\\n else{\\\\n params._source.id;\\\\n }\\\\n \\\"'] was expecting one of [{<EOF>, ';'}].\"}}}]},
I have tried first to have without tilde-character. And then it also fails.
I then tried to have tilde at the beginning, something like:
var _script = `{
Thing is that the final json that will be sent to elastic is not shown in the code above. So "_script" is only a little part of all the json.
I was wondering if I added the tilde at the very beginning and end of the whole json. Maybe it could work? I need to work it out where it is.
But just in theory: do you think the problem is there? Putting the tilde around all the json? Or is it something else?
The triple " is not valid JSON, it only works internally to the Elastic stack (i.e. from Kibana Dev Tools to ES).
The way I usually do it from Node.js is to add each line to an array and then I join that array, like this:
const code = [];
code.push("if(1>2){");
code.push("params._source.id;");
code.push("} else {");
code.push("params._source.id;");
code.push("}");
source = code.join(" ");
It's not super legible, I admit. Another way is to use stored scripts so you can simple reference your script by ID in Node.js.

nodejs+selenium-driver NoSuchElementError & StaleElementReferenceError

I am doing a test based mocha. node v8.2.1, selenium-webdriver: ^3.5.0.
test.it('demoClass', () => {
driver.classes[0].findElement(By.css('.class-avatar')).click();
driver.wait(until.elementIsVisible(driver.findElement(By.css('.anticon.anticon-plus'))));
//driver.sleep(2000);
driver.findElement(By.css('.anticon.anticon-plus')).click();
})
I am getting two different types of errors, either its NoSuchElementError: no such element: Unable to locate element: or StaleElementReferenceError: stale element reference: element is not attached to the page document
But whichever error, its refer to line:
driver.findElement(By.css('.anticon.anticon-plus')).click();
When I use driver.sleep(2000), its getting resolved. In my opinion, It's the question of animation. I can get the element(.anticon.ancicon-plus) only at the time, the page's animation is completed.
what I am confused is that I use driver.wait(until.elementIsVisible()) without an error, It's obvious that I got the element. but at the next line, I can't use it. Or NoSuchElementError, or StaleElementReferenceError.
I find some answer like http://www.seleniumhq.org/exceptions/stale_element_reference.jsp,https://stackoverflow.com/questions/18225997/stale-element-reference-element-is-not-attached-to-the-page-document. But It can't help me.
when use driver.findElement, something terrible will be triggered. use javascript instead it.
driver.executeScript(function() {
while(true) {
if(!document.querySelector('.anticon.anticon-plus')){}
else {
document.querySelector('.anticon.anticon-plus').click();
break;
}
}
return true; // not neccessary
})

Using angulars ngResource get method

I have a basic controller defined in C#, its only purpose is to return whoever the current user is.
namespace ProjectName.Controllers
{
public class UserController : ApiController
{
// GET api/user/
public string Get()
{
return User.Identity.Name;
}
}
}
I then have an ngResource defined to look at that controller
cript.factory('User', function ($resource) {
return $resource('/api/User')
});
finally I try to get that user in my Angular Controller
$scope.checkIfAuth = function () {
$scope.user = User.get();
console.log($scope.user);
if ($scope.user === '"DS//:lemieszr"') {
console.log("success");
}
};
The problem is $scope.user is a resource object that looks like this
Resource {$get: function, $save: function, $query: function, $remove: function, $delete: function}
0: """
1: "D"
2: "S"
3: "\"
4: "\"
5: "l"
6: "e"
7: "m"
8: "i"
9: "e"
10: "s"
11: "z"
12: "r"
13: """
__proto__: Resource
Is there anyway to just get the string containing my Username. User.query() only returns an empty array.
I would advise looking into Angular's implementation of Kris Kowal's Q promise library ($q). I'm working with mvc 4.0 right now as well and I have found it to be much more flexible than ngResource.
However with respect to your question specifically, your issue here is you are making an async request to your server while synchronously invoking its response. Well, the data hasn't gotten there yet (why you are seeing an empty array []). That empty array is basically the server saying "Hey, good work following protocol on your http request, we are getting your data, to prove it to you here is an empty array where we will put the data there when it gets to you."
In other words, your problem is that you are asking setting checking the value of $scope.user before it even has one (roughly speaking).
You two options for simple fixes (at least to my knowledge):
You can set $scope.user to the response from the server in a SEPARATE function, or some other service, and then use the response once it gets there. OR (the better 'simple' fix) use the $timeout service, which essentially tells your system to "chill until my async request gets done and I have my data."
User.query() returns an empty array because it needs an array of json objects [{...},{...}] as a response from your back-end. User.get assumes that your server returns an object like {"name":"Andi"} for example, so if your server response is correct there is no problem with get method.
$scope.user = User.get();
Than you have access to you name property as $scope.user.name
This plumk may help you link

XMLSlurper appendNode does not see changes

I am having troubles using XMLSlurper to update an XML document. Most things work, but in some situations a "find" doesn't find a Node I just appended (appendNode). The new Node is there at the end of processing, but is not found when I am in the middle of adding children.
I found a post about XMLSlurper that says that finding the new Node requires calling parseText again and/or StreaMarkupBuilder (see below). Really?! That seems so kludgy that I thought I'd verify on SO.
Here is a code snippet. The "find" gets NoChildren even though the Node was just added.
codeNode.appendNode {
'lab:vendorData'() {}
}
vendorNode = codeNode.children().find { it.name() == "vendorData" }
"appendNode doea not modify the slurped document directly. The edit is applied "on the fly" when the document is written out using StreamingMarkupBuilder."
http://markmail.org/message/5nmxbhwna7hr5zcq#query:related%3A5nmxbhwna7hr5zcq+page:1+mid:bkdesettsnfnieno+state:results
Why can't I find my new Node?!
This is what I got to work. Is not elegant, but got past "update" problem:
...
codeNode.appendNode {
'lab:vendorData'() {}
}
//-- must re-slurp to see appended node
labDoc = new XmlSlurper().parseText(serializeXml(labDoc))
codeNode = getResultNodeFor( nextResult.getCode() );
vendorNode = codeNode.children().find { it.name() == "vendorData" }
...
def String serializeXml(GPathResult xml){
XmlUtil.serialize(new StreamingMarkupBuilder().bind {
mkp.declareNamespace("lab", "www.myco.com/LabDocument")
mkp.yield labDoc
} )
}

Resources