If I try to log something else it again stops working. I tried putting it at the end of the function and it works. It has to be there. What's going on?
async function fetchData() {
const response = await client.query(query).toPromise();
setPoolSnapshots(response.data.poolSnapshots);
console.log(poolSnapshots[0].totalLiquidity); //breaks without this line.
poolSnapshots?.map((poolInfo, _index) => (
dates.push(poolInfo.timestamp),
swapFeesEarned.push(poolInfo.swapFees24h)
))
swapFeesEarned?.map((swapFee, _index) => (
swapFeesApr.push((swapFee *365) / poolSnapshots[_index].totalLiquidity * 100)
))
dates?.map((date, _index) => (
dates[_index] = new Date(date * 1000).toLocaleDateString()
))
};
Related
I want to edit a message, but it's only updated when i changed this message _id. Can someone provide me how to do it, here is my code:
const onSend = useCallback((messagesToSend = []) => {
if(editMessage != null){
setEditMessage()
const m = messagesToSend[0]
const newMessages = [...messages]
const index = newMessages.findIndex(mes => mes._id === editMessage._id);
console.log('index: ', index)
if(index > -1){
newMessages[index].text = m.text // => ***i only edit the text***
// newMessages[index]._id = uuid.v4() => ***this working if changed _id***
console.log('newMessages', newMessages[index]) // => ***new message changed it's text but the bubble not change when re-render***
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
setMessage(newMessages)
}
}else{
setReplyMessage()
appendMessage(messagesToSend)
}
})
It looks like you're using useCallback without a dependency array. This means that any dependencies that you rely on will be memoized and won't update when you run the function.
You should add messages, editMessage, and maybe setMessage and appendMessage, to the dependency array. Like so:
const onSend = useCallback(
(messageToSend = []) => etc,
[messages, editMessage, setMessage, appendMessage]);
That's the first thing I would try
ok i found problem, in MessageText the function componentShouldUpdate need modify a bit
I see this question has been posted multiple times but all of the examples I've tried are not working.
I want to limit the search by keywords to only search for exact word not a phrase or mixed content, so if I search for cheese It need to be limited only for word cheese, right now it will return content with word cheeseburger also.
The part of the search query in my modified template query is right here:
if ( 'featured' === $args['orderby'] ) {
$query_args['orderby'] = [
'menu_order' => 'ASC',
'date' => 'DESC',
'ID' => 'DESC',
];
}
if ( 'rand_featured' === $args['orderby'] ) {
$query_args['orderby'] = [
'menu_order' => 'ASC',
'rand' => 'ASC',
];
}
$job_manager_keyword = sanitize_text_field( $args['search_keywords'] );
if ( ! empty( $job_manager_keyword ) && strlen( $job_manager_keyword ) >= apply_filters( 'job_manager_get_listings_keyword_length_threshold', 2 ) ) {
$query_args['s'] = $job_manager_keyword;
//add_filter( 'posts_search', 'get_job_listings_keyword_search' );
}
$query_args = apply_filters( 'job_manager_get_listings', $query_args, $args );
if ( empty( $query_args['meta_query'] ) ) {
unset( $query_args['meta_query'] );
}
if ( empty( $query_args['tax_query'] ) ) {
unset( $query_args['tax_query'] );
}
/** This filter is documented in wp-job-manager.php */
$query_args['lang'] = apply_filters( 'wpjm_lang', null );
// Filter args.
$query_args = apply_filters( 'get_job_listings_query_args', $query_args, $args );
do_action( 'before_get_job_listings', $query_args, $args );
I can see that $query_args['s'] is standard query for search keywords but some standard query modifications I've tried like this examples
https://wordpress.stackexchange.com/questions/177183/make-a-wp-query-search-match-exactly-the-search-term/17786
WordPress exact search query
Query for exact word search
And other examples too, none of them are working for me.
Anyone have an idea how i can modify it so it can search only for exact word in content?
I am trying to create a LinkedHashMap and populate it with a DateTime as the key and a List as the value in my flutter app. I keep running into problems with creating this.
Here is what I am trying right now without success:
List<dynamic> _getEventsForDay(DateTime day) {
for (int i = 0; i < eventDoc.length; i++ ) {
if (day.year == eventDate.year && day.day == eventDate.day && day.month == eventDate.month) {
List<dynamic> eventList = [];
eventList.add(eventDoc[i].agencyId);
eventList.add(eventDoc[i].agentId);
eventList.add(eventDoc[i].eventDate);
eventList.add(eventDoc[i].eventDescription);
eventList.add(eventDoc[i].eventDuration);
eventList.add(eventDoc[i].eventName);
eventList.add(eventDoc[i].eventStartTime);
return kEvents.putIfAbsent(eventDateUTC, () => eventList);
}
}
}
Everything is working except the last line and the putIfAbsent call. The eventDateUTC and the eventList both have values.
I am getting this error when I try to execute the
return kEvents.putIfAbsent(eventDateUTC, () => eventList);
line. When this line executes I get this error:
The method 'putIfAbsent' was called on null.
Receiver: null
Tried calling: putIfAbsent(Instance of 'DateTime', Closure: () => List<dynamic>)
kEvents is declared like this:
LinkedHashMap<DateTime, List> kEvents;
I am sure I am missing something small but I don't have enough experience with flutter to know what it is. Please help if you can.
I'm experiencing early termination of the AkkaSystem after first record being read ,entering into the Dead letter without executing the task for all the records
I have 10records in my file , 2 of the records has the matching filename to be pushed to s3.
what could be going wrong here. Please suggest
Sample file record:
xxxxx,ABC,2019-05-10 00:11:00
yyyyyy,XYZ,2019-05-10 00:41:00
import akka.actor.{Actor, ActorSystem, Props}
import scala.io.Source
import scala.sys.process._
class HelloActor extends Actor {
def receive: Receive = {
case line: String => {
// print("Ahshan"+line)
val row = line.split ( "," )
val stdout = new StringBuilder
val stderr = new StringBuilder
val status = Seq ( "/bin/sh", "-c", "ls /Users/ahshan.md/Downloads/".concat ( row ( 2 ).substring ( 0, 10 ) ).concat ( "/*" ).concat ( row ( 0 ) ).concat ( "*" ) ) ! ProcessLogger ( stdout append _, stderr append _ )
// println(status)
// println("stdout: " + stdout)
// println("stderr: " + stderr)
if (status == 0) {
println ( "/bin/sh", "-c", "aws s3 cp ".concat ( stdout.mkString ).concat ( " " ).concat ( "s3://ahshan/".concat ( row ( 1 ) ).concat ( "/" ).concat ( row ( 0 ) ).concat ( ".email" ) ) )
}
else {
// println ( "File Not Found: " + row ( 0 ), row ( 1 ), row ( 2 ).substring ( 0, 10 ) )
println ( "stderr: " + stderr )
}
}
case "finished" => println ( "Hello Ahshan" )
case _ => println ( "Exiting" )
}
}
object AkkaHelloWorld extends App {
// an actor needs an ActorSystem
val system = ActorSystem ( "HelloSystem" )
// create and start the actor
val helloActor = system.actorOf ( Props [HelloActor], name = "helloActor" )
try {
val filename = "/Users/ahshan.md/Downloads/test.txt"
for (line <- Source.fromFile ( filename ).getLines) {
helloActor ! line
}
}
finally {
system.terminate ()
}
}
The ActorSystem and the actors run concurrently with your main thread, sending a message to an actor is async and the sending thread immediately continues, it does not wait for the actor to process the message.
This means that in your code the main thread fires off each line to the actor as fast as it can and then terminates the actor system. In this example it could make sense to move the termination logic into the actor and let the actor terminate the system when it has completed.
That will only work as long as your application is a single actor though, as soon as you add another actor you will have to revisit how you terminate the system.
As an additional note using the process API in Scala like that will block until the process has completed, calling blocking code can have bad consequences, read this section of the docs for more details: https://doc.akka.io/docs/akka/current/typed/dispatchers.html#blocking-needs-careful-management
I have an observable which might throw an error. When it throws, I want to resubscribe to that observable and try again. For example with the retry() operator.
To test this retry-logic I would need to create a test-observable which will throw an error the first 2 times it's subscribed to, and only on 3rd time would produce a value.
I tried the following:
import { Observable } from 'rxjs';
import { TestScheduler } from 'rxjs/testing';
import { retry } from 'rxjs/operators';
// Setup for TestScheduler
function basicTestScheduler() {
return new TestScheduler((actual, expected) => {
expect(actual).toEqual(expected);
});
}
// The function we're going to test
function retryMultipleTimes(observable$) {
return observable$.pipe(retry(2));
}
describe('retryMultipleTimes()', () => {
it('retries twice when observable throws an error', () => {
basicTestScheduler().run(({ hot, cold, expectObservable }) => {
const observable$ = hot('--#--#--Y');
const expected = ' --------Y'; // This is what I want to get
const unexpected = ' --# '; // This is what I get instead
expectObservable(retryMultipleTimes(observable$)).toBe(expected);
});
});
});
Seems that with a hot() observable it always resubscribes to the same frame that produced the error, resulting in immediately throwing again.
I also tried with cold() observable, in which case I get ------# - that is, at each retry the observable starts again from the beginning, resulting in --#, --#, --# - never reaching --Y.
It seems that there isn't a way to do such a thing with RxJS TestScheduler. Or perhaps there is?
If the hot() and cold() observable-creators aren't up to the task, perhaps I can create my own... but how?
I also tried adding a little delay between retries, so I wouldn't resubscribe immediately to the current frame by implementing the retry-logic using retryWhen:
function retryMultipleTimes(observable$) {
return observable$.pipe(
retryWhen(errors => errors.pipe(
delayWhen(() => timer(2)), // wait 2 frames before each retry
take(2), // do maximum of 2 retries
concat(throwError('error')), // finish with error when no success after 2 retries
)),
);
}
But this didn't work either. Looks like the resubscription still happens to the same frame as before.
How could I make this test pass?
Figured out a solution for this. I can use iif() to create an observable which chooses at subscription time between two observables:
describe('retryMultipleTimes()', () => {
it('retries twice when observable throws an error', () => {
basicTestScheduler().run(({ cold, expectObservable }) => {
let count = 0;
const observable$ = iif(
() => ++count <= 2,
cold('--#'),
cold('--Y'),
);
// --#
// --#
// --Y
expectObservable(retryMultipleTimes(observable$)).toBe('------Y');
});
});
});