lit element query() returning null - lit-element

I'm using the query() to reference a lit element. For example
#query('#first')
_first;
However, that lit element hasn't been rendered to the dom yet and the #first returns null. When I do this._first = null. What can I do to make sure that first is not null? How can I wait for the lit element to be rendered to the dom?

As you mentioned, #query will return null before the initial update has completed because the element hasn't rendered yet.
One possible option is to use the #queryAsync decorator. Instead of returning your element or null synchronously, it returns a promise that resolves to the queried node after any pending render is completed.
Another option is to await this.updateComplete which also lets you wait for any pending updates to complete before querying the rendered DOM. E.g. from the linked updateComplete docs: "When writing tests you can await the updateComplete Promise before making assertions about the component’s DOM."
await this.updateComplete; // Wait for pending update to render #first
this._first // Result of querying for #first on rendered DOM in this.renderRoot.

Related

Nodejs (Infinispan) : Does Infinispan put method returns null for key inserted in cache for first time?

I have been reviewing the infinispan documentation and overloaded put method returns the value being replaced, or null if nothing is being replaced.
I am using overloaded put method with nodejs and it's not returning expected data, getting undefined.
how can I achieve this with nodejs?
Looked at the documentation, need assistance to understand the behavior with Nodejs
Documentation Link : https://docs.jboss.org/infinispan/9.2/apidocs/org/infinispan/commons/api/BasicCache.html#put-K-V-
V put(K key,
V value,
long lifespan,
TimeUnit unit)
An overloaded form of put(Object, Object), which takes in lifespan parameters.
Parameters:
key - key to use
value - value to store
lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
unit - unit of measurement for the lifespan
Returns:
the value being replaced, or null if nothing is being replaced.
Looked at the documentation, need assistance to understand the behavior with Nodejs
From https://github.com/infinispan/js-client/blob/main/lib/infinispan.js#L327 it looks like put's third argument opts can have property previous that makes it return the old value, so try:
const oldValue = client.put('key', 'value', { previous: true })

How to merge results from `await page.on('response')` to main result?

I am scraping for a sharable Google Map link.
On the first load, the map only shows 20 items max. After which, scrolling the scrollbar loads an additional 20.
The first 20 are first added to the results object/array. Then, to get the additional items not loaded:
I use the
await page.on('response', async (response) => {
// i will loop through each entry, and then append it to my results variable.
}
to check for the ajax request and extract the JSON result.
However, I realize that at the end of my code, the data from the ajax request do not get added to the results variable.
I believe this is because it is returned earlier, and the async call for page.on only runs after I've returned it.
How can I merge the results from my page.on into a variable, and then finally return the final results variable containing data from the async function as well?

Tabulator setHeaderFilter before inital AJAX call?

I am trying to set a default headerFilter value before the table loads. I tried all the way up to tableBuild callback. Still getting 2 calls to the API, one for the regular non-filtered data then one with the default filter. The column initialValue and defaultValue params do not seem to affect filterHeaders which is why I am going down this rabbit hole.
tableBuilt: function () {
console.log("tableBuilt");
this.setHeaderFilterValue("status", "Inactive");
}
Try the initialHeaderFilter value during table creation.
initialHeaderFilter: [{field: 'fieldName', value: 'filter value'}]
http://tabulator.info/docs/4.6/filter#header
Here is a working example.
https://jsfiddle.net/nrayburn/r319zaep/40/

How to limit .once('value) in firebase-admin node.js

How do I limit .once('value') in firebase-admin?
Code:
async function GetStuff(limit, page){
const data = await ref.limitToFirst(parseInt(limit)).once('value')
return data.val();
}
I wanted to create a page system, where a it sends request for a limited amount of data, and the user can change the page to get different data, but for some reason, I can't get it to work.
The code above only gets the first 20(when limit is 20), but how can I make it start at 20, so I can make this page feature.
I thought:
Code:
async function GetStuff(limit, page){
const data = await ref.startAt(limit*page).limitToFirst(parseInt(limit)).once('value')
return data.val();
}
You might want to review the relevant documentation. It looks like you're trying to pass the offset of a child to startAt, but that's not how startAt works. It accepts the actual value of the child to start at. Pagination by offset index is not supported.
The way you use startAt is typically passing the last sorted value retrieved by the prior query (or, if you don't want to retrieve that value again, 1 + that value, or a string that is lexically greater than the last string received. As such, some data sets might actually be difficult to paginate if they have the same sorted value repeated many times.

Why is my Watir::Table not found?

I'm using Watir-5.0.0, selenium-webdriver-2.40 and testing on IE-8. When I execute the following code:
puts "#browser.tables.length=#{#browser.tables.length}"
#browser.tables.each { |t| puts t.to_s }
t=#browser.table(:class => "jrPage")
puts "jrPage=#{t}"
t.rows.each do |row|
# do something
end
I get the following results:
#browser.tables.length=5
#<Watir::Table:0x3921cc0>
#<Watir::Table:0x3921c48>
#<Watir::Table:0x3921c00>
#<Watir::Table:0x3921bd0>
#<Watir::Table:0x3921b88>
jrPage=#<Watir::Table:0x39219d8>
Selenium::WebDriver::Error::StaleElementReferenceError: Element is no longer valid
Any thoughts on why is table I explicitly locate, Watir::Table:0x39219d8, is not in the #browser.tables.each collection?
I can understand why I get the StaleElementReferenceError (table not found) but not why the table I explicit locate isn't in the tables list.
I can find this table in the HTML.
The code is calling to_s for the table object. Watir-webdriver does not specifically define this method for elements. Therefore, it calls Ruby's default Object#to_s method:
Returns a string representing obj. The default to_s prints the
object’s class and an encoding of the object id. As a special case,
the top-level object that is the initial execution context of Ruby
programs returns “main.”
As you can see, this is what Watir is doing - Watir::Table is the object's class and 0x39219d8 is an encoding of the object id.
When iterating through the tables or getting a table, you are retrieving the table from scratch. In other words, a new table object is created for each of these commands. Even if you run the collection again, you will see that you get 4 different table object ids each time.
Note that while the table objects you are seeing are unique, the jsPage is referring to one of the elements in the collection. You can use the == method to check if two objects are referencing the same html element.
For example, you can see this with:
# Get the specific jrPage
jrPage = browser.table(:class => "jrPage")
# Check which element in the collection is the jrPage
browser.tables.each { |t| puts t == jrPage }
#=> false
#=> false
#=> true
#=> false
#=> false
The above tells you that the jrPage is the 3rd table on the page.

Resources