Konvajs - findone() function behaviour has changed between 2.0.2 and 2.4.2 - konvajs

I have a piece of code that worked just fine with Konvajs.2.0.2.
var startCity = mainStage.findOne('#0');
It would return the node with the ID=0. Works like a charm in the 2.0.2 version.
But know when I udpate to 2.4.2, this does not find the node anymore and returns a JS error (object undefined). It works for any other IDs on the map (2,3,4,etc).
I checked and printed all the node and there is definitely one with ID=0;
Any information or clue on what could have changed in the find() or findone() function between those 2 releases? Is it something like you cannot have an ID=0 anymore maybe?
Thank you.

The behavior was slightly changed.
Now id cannot have values that == null (like empty string or 0).
To fix the issue you can convert number 0 to string "0". Or use another id.

Related

getFullYear() is not a function

I am developing web app by using Angular. When I upgrade my app to Angular7, Date function is not working. It gave me error such as
DateTime.getFullYear is not a function
It was ok before I upgraded to Angular7. In package.json:
"typescript": "^3.1.1", "#angular/cli": "~7.0.2",
"#angular/complier-cli": "~7.0.0".
What is going on?
Remember next time you post a question to paste the code relating to your error so that someone can have a look at it, since the same error can result from different code.
After upgrading my ng6 app to ng7 my DateTime.getFullYear worked fine, until I changed something about it, and it suddenly gave the same error. Everything seemed fine.
Checking my date object like below returned an object just the way it should
dateFunction(longdate) {
console.log(typeof(longDate)) // This returned 'object' which is correct
longDate.getFullYear() // Would get the same error here
}
So I tried passing in a fresh date object into the function, and not one being send via parameter like this:
dateFunction() {
longDate = new Date();
console.log(typeof(longDate)); // This returned 'object' which is correct
longDate.getFullYear(); // This worked fine now
}
And this would work fine, so I realized it is not my getFullYear() function that is wrong, but my parameter that is corrupt.
But here is the strange part, so I went to the parent component and did the same thing there - I deleted the old code and made a fresh longDate = new Date() and send it through to my function, and suddenly it was working. The exact same code, but I just re-wrote it.
Try creating a fresh date just before your function, pass it in and see if it works. If it works then it is not your function but the old date variable that is corrupt.
PS: I just feel that I have to say that you must use the new keyword (see examples above) when creating your initial date variable, or it will also throw the error...

urlmappings changes - grails 2 to 3 upgrade

I have the following mapping in my UrlMappings.groovy:
"/$controller/$action?/$id?/$id2?/$id3?" {constraints {}}
Given a request url xcontroller/xaction/xid1//xid3 ( note // )
grails 2.x would produce values for id and id3 but not id2. this is what i would have expected.
In grails 3.2.5, this url only produces id1 and id2 values ( xid3 becomes id2 ). It appears the // is ignored.
Have others experienced this issue? Is it a bug or desired change?
I consider the old behavior a bug and the new behavior as preferred. Empty path segements like // should get resolved to nothing, and further all of the following URLs should be equivalent:
http://host/foo/bar
http://host/foo//bar
http://host/foo/./bar
RFC3986 discusses URI syntax.
You could use a dummy value like 0 as a placeholder for "missing" components.

Arel + Rails 4.2 causing problems (bindings being lost)

We recently upgraded to Rails 4.2 from Rails 4.1 and are seeing problems with using Arel + Activerecord because we're getting this type of error:
ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR: bind message supplies 0 parameters, but prepared statement "" requires 8
Here's the code that is breaking:
customers = Customer.arel_table
ne_subquery = ImportLog.where(
importable_type: Customer.to_s,
importable_id: customers['id'],
remote_type: remote_type.to_s.singularize,
destination: 'hello'
).exists.not
first = Customer.where(ne_subquery).where(company_id: #company.id)
second = Customer.joins(:import_logs).merge(
ImportLog.where(
importable_type: Customer.to_s,
importable_id: customers['id'],
remote_type: remote_type.to_s.singularize,
status: 'pending',
destination: 'hello',
remote_id: nil
)
).where(company_id: #company.id)
Customer.from(
customers.create_table_alias(
first.union(second),
Customer.table_name
)
)
We figured out how to solve the first part of the query (running into the same rails bug of not having bindings) by moving the exists.not to be within Customer.where like so:
ne_subquery = ImportLog.where(
importable_type: Customer.to_s,
importable_id: customers['id'],
destination: 'hello'
)
first = Customer.where("NOT (EXISTS (#{ne_subquery.to_sql}))").where(company_id: #company.id)
This seemed to work but we ran into the same issue with this line of code:
first.union(second)
whenever we run this part of the query, the bindings get lost. first and second are both active record objects but as soon as we "union" them, they lose the bindings are become arel objects.
We tried cycling through the query and manually replacing the bindings but couldn't seem to get it working properly. What should we do instead?
EDIT:
We also tried extracting the bind values from first and second, and then manually replacing them in the arel object like so:
union.grep(Arel::Nodes::BindParam).each_with_index do |bp, i|
bv = bind_values[i]
bp.replace(Customer.connection.substitute_at(bv, i))
end
However, it fails because:
NoMethodError: undefined method `replace' for #<Arel::Nodes::BindParam:0x007f8aba6cc248>
This was a solution suggested in the rails github repo.
I know this question is a bit old, but the error sounded familiar. I had some notes and our solution in a repository, so I thought I'd share.
The error we were receiving was:
PG::ProtocolViolation: ERROR: bind message supplies 0 parameters, but
prepared statement "" requires 1
So as you can see, our situation is a bit different. We didn't have 8 bind values. However, our single bind value was still being clobbered. I changed the naming of things to keep it general.
first_level = Blog.all_comments
second_level = Comment.where(comment_id: first_level.select(:id))
third_level = Comment.where(comment_id: second_level.select(:id))
Blog.all_comments is where we have the single bind value. That's the piece we're losing.
union = first_level.union second_level
union2 = Comment.from(
Comment.arel_table.create_table_alias union, :comments
).union third_level
relation = Comment.from(Comment.arel_table.create_table_alias union2, :comments)
We created a union much like you except that we needed to union three different queries.
To get the lost bind values at this point, we did a simple assignment. In the end, this is a little simpler of a case than yours. However, it may be helpful.
relation.bind_values = first_level.bind_values
relation
By the way, here's the GitHub issue we found while working on this. It doesn't appear to have any updates since this question was posted though.

Array.size() returned wrong values (Grails)

I'm developing an app using Grails. I want to get length of array.
I got a wrong value. Here is my code,
def Medias = params.medias
println params.medias // I got [37, 40]
println params.medias.size() // I got 7 but it should be 2
What I did wrong ?
Thanks for help.
What is params.medias (where is it being set)?
If Grials is treating it as a string, then using size() will return the length of the string, rather than an array.
Does:
println params.medias.length
also return 7?
You can check what Grails thinks an object is by using the assert keyword.
If it is indeed a string, you can try the following code to convert it into an array:
def mediasArray = Eval.me(params.medias)
println mediasArray.size()
The downside of this is that Eval presents the possibility of unwanted code execution if the params.medias is provided by an end user, or can be maliciously modified outside of your compiled code.
A good snippet on the "evil (or lack thereof) of eval" is here if you're interested (not mine):
https://javascriptweblog.wordpress.com/2010/04/19/how-evil-is-eval/
I think 7 is result of length of the string : "[37,40]"
Seems your media variable is an array not a collection
Try : params.medias.length
Thanks to everyone. I've found my mistake
First of all, I sent an array from client and my params.medias returned null,so I converted it to string but it is a wrong way.
Finally, I sent and array from client as array and in the grails, I got a params by
params."medias[]"
List medias = params.list('medias')
Documentation: http://grails.github.io/grails-doc/latest/guide/single.html#typeConverters

Lua arguments passed to function in table are nil

I'm trying to get a handle on how OOP is done in Lua, and I thought I had a simple way to do it but it isn't working and I'm just not seeing the reason. Here's what I'm trying:
Person = { };
function Person:newPerson(inName)
print(inName);
p = { };
p.myName = inName;
function p:sayHello()
print ("Hello, my name is " .. self.myName);
end
return p;
end
Frank = Person.newPerson("Frank");
Frank:sayHello();
FYI, I'm working with the Corona SDK, although I am assuming that doesn't make a difference (except that's where print() comes from I believe). In any case, the part that's killing me is that inName is nil as reported by print(inName)... therefore, myName is obviously set to nil so calls to sayHello() fail (although they work fine if I hardcode a value for myName, which leads me to think the basic structure I'm trying is sound, but I've got to be missing something simple). It looks, as far as I can tell, like the value of inName is not being set when newPerson() is called, but I can't for the life of me figure out why; I don't see why it's not just like any other function call.
Any help would be appreciated. Thanks!
Remember that this:
function Person:newPerson(inName)
Is equivalent to this:
function Person.newPerson(self, inName)
Therefore, when you do this:
Person.newPerson("Frank");
You are passing one parameter to a function that expects two. You probably don't want newPerson to be created with :.
Try
Frank = Person:newPerson("Frank");

Resources