Version française
Home     About     Download     Resources     Contact us    
Browse thread
React.E.switch issue.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Guillaume Yziquel <guillaume.yziquel@c...>
Subject: React.E.switch issue.
Hello.

Here is a piece of code that I am having issue. I'm trying to use React 
to parse reactively a server output. I have the following event definition:

>   let event_starting_at str = React.E.fold begin fun accu chunk -> accu^chunk end str received_event in 
>   let to_be_parsed_event_of_event, set_to_be_parsed_event_of_event = React.E.create () in
>   let to_be_parsed_event = React.E.switch (event_starting_at "") to_be_parsed_event_of_event in
>   let reinitialise_with unparsed_text = set_to_be_parsed_event_of_event (event_starting_at unparsed_text) in

String chunks from the server are received by the 'received_event' 
event, on the first line.

My issue is that the 'reinitialise_with' function is called in a 
function 'phi' which is used in the following way:

let message_event = React.E.map phi to_be_parsed_event.

phi is the parsing function, so I'm not reproducing it directly here. 
However, you would have the behaviour described further below with the 
following code:

let phi string_chunk =
   let new_string_chunk = String.copy string_chunk in
   reinitialise_with new_string_chunk;
   new_string_chunk

This creates hiccups in the events.

For example, at different time intervals, with to_be_parsed_event, I get:

	q
	qqw
	qqwwe
	qqwweer
	qqwweerrt

etc... where I'd like in fact to have

	q
	qw
	qwe
	qwer
	qwert

Advice would be appreciated on how to correct this.

All the best,

-- 
      Guillaume Yziquel
http://yziquel.homelinux.org/