RX threadding issues in WinRT - windows-runtime

I have some simple code:
var timer = Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1)).Timestamp();
//timer.Subscribe(x => timerTb.Text = x.Value.ToString());
timer.Subscribe(x => Debug.WriteLine(x.Value));
And a textbox on the view called timerTb. I am trying to get the commented out line to work without it shouting about marshalling issues.
From what i can find out i should be using timer.ObserveOnDispatcher().Subscribe(...
But i do not have access to this method, nor do i have access to the CoreDispatcherScheduler dispite referencing "System.Reactive.Linq;"
I am running RX 2.0.20304.0
Any ideas?

I managed to get it working.
Silly rookie mistake CoreDispatcherScheduler was in : System.Reactive.Windows.Threading
Once i referenced that i got ObserveOnDispatcher() and this worked:
var timer = Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1)).Timestamp();
timer.ObserveOnDispatcher().Subscribe(x => timerTb.Text = x.Value.ToString());

Put your timer on the UI thread:
Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1), CoreDispatcherScheduler.Instance)
.Timestamp();

Related

Devextreme dxo-item-dragging: error any method call from method onDragEnd

I cannot access any value in typescript inside the function triggered by the onAdd event of the dxo-item-dragging element. All come undefined
HTML Code :
<dxo-item-dragging group="'server'" [data]="tasks"
[allowReordering]="true" [onDragStart]="onDragStart" [onAdd]="onAdd" [onRemove]="onRemove">
</dxo-item-dragging>
TS Code:
onAdd(e) {
e.toData.splice(e.toIndex, 0, e.itemData);
let a = this.tasks;
}
When I do let a = this.tasks, this.tasks comes as undefined. Actually I defined it.
When I type [onAdd]="onAdd.bind(this)" instead of [onAdd]="onAdd", I can access all properties, but this time the ui slows down a lot and freezes.
Thanks in advance for your help
I tried binding the event event to a function.
I was expecting to access all properties in that function, but I can't.
in the example in this link https://js.devexpress.com/Demos/WidgetsGallery/Demo/DataGrid/DnDBetweenGrids/Angular/Light/ there is a solution to my problem. For those who have the same problem as me, the solution to my problem is to put
this.onAdd = this.onAdd.bind(this);
It was enough for me to write. Have a nice day

*ngIf or [hidden] not working correctly

I'm trying to allow for hiding of certain sections of the project I'm working on via user toggle. It saves in the database and gets pulled when the page is loaded in the constructor using the following code
this.http.get(`api/section/get/${this.id}`, this.id).subscribe(res => {
this.section = res.json()[0];
this.sect = res.json();
console.log(this.section);
this.hideIntro = this.sect[0].hideIntro;
this.hideMainVideo = this.sect[0].hideMainVideo;
this.hideHandout = this.sect[0].hideHandout;
this.hideQuiz = this.sect[0].hideQuiz;
console.log("Hide Intro = " + this.hideIntro);
console.log("Hide Main = " + this.hideMainVideo);
console.log("Hide Handout = " + this.hideHandout);
console.log("Hide Quiz = " + this.hideQuiz);
});
The HTML is as follows...
<div class="row classMainBackground col-md-12" *ngIf="!hideIntro">
...content...
</div>
For some reason, no matter what I do, whether I change it to *ngIf="hideIntro == false" or even use [hidden]="hideIntro", it is not working.
Even the console logs in the .ts file show up correctly. Is there a reason why this is not working for me? I've used it in other positions and it works fine there...
Does it have something to do with assigning it in the constructor or something?
Thanks in advance!
Angular change detection runs in response to use interaction with the component. If values are updated outside of that event handling (such as after an HTTP request), you need to manually tell the component that it has changed.
constructor(private changeDetector: ChangeDetectorRef){}
this.http.get(`api/section/get/${this.id}`, this.id).subscribe(res => {
[...]
this.changeDetector.markForCheck();
})
More in depth reading: https://blog.thoughtram.io/angular/2016/02/22/angular-2-change-detection-explained.html
I ended up solving the problem by using {{!section.hideIntro}} in the HTML instead of trying to define a new variable to pass that boolean to.
I believe the answer was a combination of what #Vlad274 and #ConnorsFan were mentioning.
the HTML was returning an [object object] for {{hideIntro}} and it seems like there's a delay between the assigning the new value data from the GET response before the DOM actually loads.
Grabbing the data right from the GET respone variable ended up doing the trick.

adding a new class using a for loop to determine which class specifically to add

I made this account to ask this question because researching strings and testing a whole ton of different things ended up with nothing working. You should be able to see what I am trying to do with this code piece here that is not working for me. If I hard type out "Level1" instead of "Level[i]" everything works fine.
for (var i = 0; i<=100; i++)
{
if (levelOn == i)
{
var Lv:Level[i] = new Level[i];
addChild(Lv)
}
}
I have 100 level files labeled "level1", "level2", etc in the project folder. I am trying to access a certain level via using a forloop to add a certain level to the screen (levelOn = 56 means the compiler would add the class "Level56" to the screen.)
I think I have the right idea but I cannot get it to work, all I get is this error
Line 24 1086: Syntax error: expecting semicolon before leftbracket.
If someone has a more efficient way of accessing a "level" in a application (where it has the same base class but minor differences) please send me in the right direction.
Thanks!!!!!
Try this:
var i:int;
var Lv:Level[i] = new Level[i];
addChild(Lv)
for (i=0; i<100; i++){
if(LevelOn=i)
}

HTML is not updated when using Mootools dragging

I'm using Mootools (don't think it is related to the problem) to drag and drop and element.
var draggable = new Drag(timeHandle, {
onDrag: function () {
var calculatedTime = calcTime();
$('timeLabel').innerHTML = calculatedTime;
},
});
Basically, I can drag my 'timeHandle' and the 'timeLabel' is getting updated properly.
The problem is that sometimes, after moving the handle a little bit, suddently, the UI is not getting updated. The 'timeHandle' is not moving and the 'timeLabel' is not getting updted.
The problem is not with the drag event, I can see it keeps on getting called.
When I move
$('timeLabel').innerHTML = calculatedTime;
everything works fine.
So, the problem is not with the 'Drag' object since the event is kept on calling.
Looks like some UI performance issue.
Thanks
To simplify your code, you can use Element.set('text', 'my text here');
var element = $('timeLabel');
var draggable = new Drag(timeHandle, {
onDrag: function () {
element.set('text', calcTime());
}
});
Also, remember to remove that last comma or it will throw errors in Internet Explorer.
OK, found a to make it work.
I still not sure what caused the problem but it looks like the 'innerHTML' command has either really poor performance which causes problems in the GUI updates or maybe some kind of internal mechanism (IE only? which is supposed to prevent the UI from updates overflow.
Anyway, instead of using the innerHTML, I'm doing the following:
var draggable = new Drag(timeHandle, {
onDrag: function () {
var calculatedTime = calcTime();
var element = $('timeLabel');
element.removeChild(element.firstChild);l
element.appendChild(element.ownerDocument.createTextNode(calculatedTime));
},
});
Works like a charm

Flash QuickBox2d skinMc.gotoAndPlay(1);

I have this quickBox2d code to add a cricle to the stage:
var ball:QuickObject = sim.addCircle( {skin:skinMc, x:10, y:10, radius:3, density:0 } );
The skinMc contains animations so I want to be able to refer to it like this: skinMc.gotoAndPlay(5); but it says
Type Coercion failed: cannot convert skinMc$ to flash.display.MovieClip.
ball.gotoAndPlay(5); doesn't work either since it's a QuickObject, not an mc...
Any help will be appreciated
Thanks
ball.userData.gotoAndPlay(5);
userData will be a DisplayObject populated by QuickBox2D.
var sim:QuickBox2D = new QuickBox2D
var ball:QuickObject = sim.addCircle( {skin:skinMc, x:10, y:10, radius:3, density:0 } );
//something along these lines
So to reference the object you can use:
sim.gotoAndPlay("5");
im not 100% on what your doin but i installed both packages and created a quick document and it works fine on my machine.
if need be try this link http://www.emanueleferonato.com/2009/08/25/simplify-your-box2d-projects-with-quickbox2d/
if this fails,send me your file or else let me know how you go.