Creating Flex Elements Server Side - apache-flex

i wonder if it is possible to pre-configurate Flex Elements on the Server. I have the Problem with a custom ItemRenderer which turns out to be very slow. It would be very cool to pre-process such an element on the server instead in the clients browser... somehow? Maybe it is possible to produce the MXML dynamically on the server for that.
This is it basically. I create a Label for each data entry in an array list. This entry is added to a BorderContainer and this goes to the containing element as a whole here. Sometimes i add 200 - 300 items this way which is costing very high computing cost at client side. So i wonderd if i could just pass this as a whole dynamic mxml element to the client.
override public function set data(value:Object):void {
_data = value as WordResultObject;
var data:WordResultObject = _data as WordResultObject;
this.removeAllElements();
if(_data!=null)
{
_l.text = data.wordform;
_l.setStyle("fontSize", data.fontSize);
_l.setStyle("color", data.color);
_l.toolTip = "Frequency: " + data.freq;
if(data.date != null)
{
_l.toolTip += "\nDate: " + AppUtils.TimeString(data.date as Date);
_l.addClickEvent(data.id as int, data.date as Date);
}
_border.addElement(_l);
this.addElement(_border);
}
}
Thank you
Andreas

I wonder if it is possible to
pre-configurate Flex Elements on the
Server.
Not that I know of. Perhaps if you go back to Flex 1 / 1.5 which was primarily a server based platform. I do not expect rolling your code back to an "old" server would improve efficiency at all, though. How would you expect this work? What benefit are you expecting to receive.
I have the Problem with a custom
ItemRenderer which turns out to be
very slow.
Show your code; and perhaps we can help you with writing your renderer to be more efficient.

Related

What could cause .wasm to load images so slowly?

In my Uno test project, it takes about 4 seconds to load 50 images into an ItemsWrapGrid on the UWP platform. The same images take 225 seconds (3 minute 45 seconds) to load into a WrapPanel. Since the only difference in the code is ItemsWrapGrid or WrapPanel, I'm thinking the problem is the WrapPanel, but I can't be sure, it could be in how the platforms implement the <Image ItemsSource=""/.
I don't have any experience with .wasm so I don't know if this is expected (is it?). Is there something I can do to Optimize for wasm?
or any other thoughts? 4- minutes is just not acceptable compared to about 4 seconds.
Thanks
Thanks for asking if I could repro in Uno Playground. I was unaware of the site.
I was NOT ABLE to repro on the playground, which led me to investigate other possibilities.
I have resolved the issue.
My design pattern was to define a single ObservableCollection without a property change notification:
public ObservableCollection<PictureViewModel> Pictures {get;set }
I would bind that to my UserControl and update by Pictures.Clear().
This is my snippet that resulted in the long render time:
List<Picture> PictList = await DataService.GetPicturesByEvent(this.SelectedEvent.EvtKey, clubkey, skipPosition, this.PagingViewModel.PageSize);
List<PictureViewModel> PictVMList = mapper.Map<List<Picture>, List<PictureViewModel>>(PictList);
if (PictVMList != null && this.SelectedEvent != null && !string.IsNullOrEmpty(SelectedEvent.FilePath))
{
this.Pictures.Clear();
foreach (PictureViewModel item in PictVMList)
{
item.Parent = this;
item.SetURL(SelectedEvent);
this.Pictures.Add(item);
}
this.SelectedPicture = PictVMList.Count > 0 ? PictVMList.First() : null;
}
To resolve the long render time. I:
Made my ObservableCollection observable.
Removed all instances of Picture.Clear();
Created a new ObservableCollection whenever it needed updating.
The Resolved code snippet is:
List<Picture> PictList = await DataService.GetPicturesByEvent(this.SelectedEvent.EvtKey, clubkey, skipPosition, this.PagingViewModel.PageSize);
List<PictureViewModel> PictVMList = mapper.Map<List<Picture>, List<PictureViewModel>>(PictList);
if (PictVMList != null && this.SelectedEvent != null && !string.IsNullOrEmpty(SelectedEvent.FilePath))
{
foreach (PictureViewModel item in PictVMList)
{
item.Parent = this;
item.SetURL(SelectedEvent);
}
this.SelectedPicture = PictVMList.Count > 0 ? PictVMList.First() : null;
}
Pictures = new ObservableCollection<PictureViewModel>(PictVMList);
I don't understand why my initial code pattern did not work as expected, but can live with adding an OnPropertyChanged("Pictures") notification.
As of Uno 3.10, ItemWrapGrid is not supported on WebAssembly. Using the WrapPanel control will force the materialization of all the items in the list, making the performance particularly slow.
You're not specifying which control you're using as a panel, but if you're using a ListView control, the virtualization will be enabled, though not with the layout wrapping that you need.
If you want virtualizing grid-like layouts, you can also use the ItemsRepeater control, and its layouts (e.g. FlowLayout, StackLayout, or WCT's WrapLayout).

Caliburn.Micro multiple element custom Conventions (NumericUpDown.Value,NumericUpDown.Maximum)

I've been messing around with CM conventions trying to understand how they work but i haven't found a decent article somewhere explaining step-by-step how and why.
However I've found a few code snippets that i've been working with with some success.
In this case, however, i don't understand what is going on.
I'm trying to bind a NumericUpDown Value and Maximum to a corresponding ViewModel property. I was able to do it with the following code:
Value
ConventionManager.AddElementConvention<NumericUpDown>(NumericUpDown.ValueProperty, "Value", "ValueChanged");
Maximum
ConventionManager.AddElementConvention<NumericUpDown>(NumericUpDown.MaximumProperty, "Maximum", "MaximumChanged");
var baseBindProperties = ViewModelBinder.BindProperties;
ViewModelBinder.BindProperties =
(frameWorkElements, viewModels) =>
{
foreach (var frameworkElement in frameWorkElements)
{
var propertyName = frameworkElement.Name + "Max";
var property = viewModels.GetPropertyCaseInsensitive(propertyName);
if (property != null)
{
var convention = ConventionManager.GetElementConvention(typeof(NumericUpDown));
ConventionManager.SetBindingWithoutBindingOverwrite(
viewModels,
propertyName,
property,
frameworkElement,
convention,
convention.GetBindableProperty(frameworkElement));
}
}
return baseBindProperties(frameWorkElements, viewModels);
};
However, an here comes the weird part, i can only make one of them to work. That makes me believe that i'm doing some noob mistake somewhere. It almost seems i can only call AddElementConvention and therefor only the last call is executed.
I would appreciate either a help with this piece of code or a reference to some good documentation that could help me with it.
Best Regards
i found out somewhere that CM only allows one convention per item so that's the reason of this behavior...
However since items like ComboBox allows binding for multiple properties (SelectedItem, ItemSource and so on...) i'm not completed convinced...

Resetting target values in a composite effect

We need to be able to handle a "playable" (play/pause/seek) effect in which the nature of the effect cannot be determined at compile time.
The problem we are running into is resetting the target(s) state after the effect has completed. If we manually drag the seek slider back to the beginning, everything works fine. However, if we set the playheadTime of the composite effect back to 0, the effected targets retain their original value until the playheadTime gets to the correct position to effect the target.
Here is a simplified (as much as I could) test case with view source enabled:
http://www.openbaseinteractive.com/_tmp/PlayableEffectTest/
The problem is demonstrated if you let it play to the end, and then hit the play button to start it over.
What is the best way to go about manually resetting the target values given that the exact nature of the effect is unknown?
Many thanks for your time!
edit
I forgot to mention we are using Flex 4.5 preview release.
Have you tried:
effect.reverse()
More info
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/effects/IEffect.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/effects/IEffect.html#reverse()
Well it's a little kludgy, but I was able to accomplish this by calling some internal methods on the effect to capture the start values, then assigned those values to the targets on a reset.
import mx.core.mx_internal;
use namespace mx_internal;
private var _propertyChangesArray:Array;
protected function captureStartValues(effect:Object):void
{
effect.captureStartValues();
_propertyChangesArray = effect.propertyChangesArray;
}
protected function reset(effect:Object):void
{
for each(var change:PropertyChanges in _propertyChangesArray)
{
var target:Object = change.target;
for(var p:String in change.start)
{
if(target.hasOwnProperty(p))
{
var startVal:* = change.start[p];
var endVal:* = target[p];
if(!isNaN(startVal) && startVal != endVal)
{
target[p] = startVal;
}
}
}
}
effect.playheadTime = 0;
}
I don't know if this is the best way to accomplish this, but it seems to be working so far. I am absolutely open to suggestions for a better method.
Cheers!

Is there some way to force 'updatedisplaylist' immediately rather than at later some point

In flex component life cycle, after we make some change in a components property, invalidation methods schedules a call to methods like commitProperties, updateDisplayList, etc for some later time. I need to call the updateDisplayList instantaneously. Is there some direct way to do this.
Currently, both the labels are changed simultaneously after completion of the loop. Instead I need it to work like this, to first render the updated 'myButton1' label then enter the loop and then update myButton2's label. I know, it is elastic race track issue, but isn't there some way to achieve this ?
myButton1.label = 'New Label1' ;
// Some logic to forcibly make the screen reflect it
for (var i:int = 0; i < 500 ; i ++){
//a dummy loop
}
myButton2.label = 'New Label2' ;
You can use myButton1.validateNow() but it's use is discouraged, for you may end up having the same component update itself multiple times on the same frame.
Use validateNow() . But, I would use it sparingly. using invalidateDisplayList() will force updateDisplayList() to run on the next renderer event.
A render event happens on each frame. 24 frames happen each second by default for Flex. Are you sure need to change these values quicker?
I would set the label for myButton1, then put the remaining code into a separate method and call that method using callLater:
private function foo():void {
myButton1.label = 'New Label1';
this.callLater(bar);
}
private function bar():void {
for (var i:int = 0; i < 500 ; i ++){ //a dummy loop
}
myButton2.label = 'New Label2';
}
This way myButton1 will update to show the new label before going into your loop since callLater doesn't call bar until after the event queue is cleared, giving myButton1 a chance to update.
invalidateDisplayList() or valdiateNow() will do it for you however excess of using these will end up memory leaks.

I want to add items to an ASP.Net combobox using Javascript

I want to add an item to an ASP.Net combobox using Javascript. I can retrieve the ID (No Masterpage). How can I add values to the combobox from Javascript? My present code looks like this.
//Fill the years (counting 100 from the first)
function fillvarYear() {
var dt = $('#txtBDate').val();
dt = dt.toString().substring(6);
var ye = parseInt(dt);
//Loop and add the next 100 years from the birth year to the combo
for (var j = 1; j <= 100; j++) {
ye += 1; //Add one year to the year count
var opt = document.createElement("OPTION");
opt.text = ye;
opt.value = ye;
document.form1.ddlYear.add(opt);
}
}
To see the value on postback:
string selectedValue = Request.Params[combobox.UniqueId]
Remember, changing the values in a combobox with javascript will cause an Event Validation exception to be thrown, and is generally a bad idea, as you'll have to explicitly disabled event validation.
I'd recommend placing the combobox in an update panel, so you can read txtBirthDate on the server and generate the appropriate data. You then won't have to manually preserve state either.
Always remember, ASP.NET controls are nothing "fancy" - they always end up at some point becoming standard HTML elements.
Try checking out this site. It has a pretty nice demo and overview. Take note however that you are altering the data at the client side - this means you will need to do it on each and every request because the ViewState will not be updated.
TBH, you are probably better off just using a HTML control rather than ASP ComboBox..
Can I ask why you are changing items via Javascript? (out of curiosity) :)
I found a possible solution. I don't know why the earlier code didn't work for me, but the line below
document.form1.ddlYear.appendChild(new Option(ye, ye));

Resources