How to read the value of a ReactNative.Style.t property with reason-react-native? - react-native

I would like to do the following:
let marginTop =
if (itemInfo##index == 0) {
Style.viewStyle(~marginTop=style##paddingTop, ());
} else {
Style.viewStyle();
}
But I get the following error:
This has type:
ReactNative.Style.t (defined as ReactNative.Style.t)
But somewhere wanted:
Js.t('a)
Does anyone knows how I can read the value?

It doesn't look too good of an idea to do it like so.
But in case you were wondering:
StyleSheet.flatten(styles)##paddingTop

Related

In anylogic. in the system dynamic. i want to use if-else

The code is like
if ( evaluaterate<1){
Deliveryrate=min(Oldproduct,ForecastCan);
else
0;
}
It says that syntax errors
Please see my comment and try to get to this:
if (evaluaterate<1)
{
Deliveryrate=min(Oldproduct,ForecastCan);
}
else
{
Deliveryrate = 0;
}
Try this:
Deliveryrate=evaluaterate<1 ? min(Oldproduct,ForecastCan) : 0;

NHibernate Criteria Filtering

I use this code to filter database records
if (!string.IsNullOrEmpty(_searchCriteria.MessageType))
{
var messageType = (AutotransferMessageType)Enum.Parse(typeof(AutotransferMessageType), _searchCriteria.MessageType, true);
if (Enum.IsDefined(typeof(AutotransferMessageType), messageType))
{
criteriaQuery.CreateAlias("AutotransferInputRecord", "AutotransferInputRecord")
.Add(
Restrictions.Eq(
"AutotransferInputRecord." + AutotransferLogSearchCriteria.MessageTypePropertyName,
messageType));
}
else
{
criteriaQuery.Add(Restrictions.IsNull("AutotransferInputRecord"));
}
}
AutotransferMessageType is enumerable type
public enum AutotransferMessageType
{
[DisplayName("MT202")]
[DatabaseName("MT202")]
MT202,
[DisplayName("MT210")]
[DatabaseName("MT210")]
MT210,
//...
}
My filter outputs the results when I enter MT202, for example. (It's the right behavior).
When I input just number, for example, 202, I get no results (It's the right behavior too).
But when I try to input some line, "mt", for example, I get error
Unexpected application error has been occured:
'Requested value 'mt' was not found.'
How to make the filter do not show any results when I input a line?
Your error is coming from the line that parses the enum. Use Enum.TryParse instead:
AutotransferMessageType msgEnum;
var enumPrasedOk = Enum.TryParse(_searchCriteria.MessageType, true, out msgEnum);
if(enumPrasedOk){
//Do something
}else{
//Handle case where enum was not found for some reason (if need be)
}
Also please note that you can not look up the enum this way using it's description (in your case they are the same so it is ok).

Creating level codes with action script 2.0

I want to create level codes, like in sea of fire (http://armorgames.com/play/351/sea-of-fire)
I have a text input box with the instance name "code" and a button that has this code:
on (release) {
if (code = 96925) {
gotoAndStop(4);
}
if (code = 34468) {
gotoAndStop(5);
}
if (code = 57575) {
gotoAndStop(6);
}
if (code = 86242) {
gotoAndStop(7);
}
if (code = 99457) {
gotoAndStop(8);
}
if (code = 66988) {
gotoAndStop(10);
}
if (code = !96925 && !34468 && !57575 && !86242 && !99457 && !66988) {
gotoAndStop(3);
}
}
I've tried to use code.text instead of just code, I've also tried quotes around the numbers, also I tried both together but it always sends you to frame 10 even if the code is invalid.
You need to use conditional operator (==), not equality operator (=) in 'if' condition
Also if 'code' is a text field then you need to use code.text
You can put trace to check for the value of code.
I do not understand your last if condition
Instead you can use if - else if - else here.

Determing if a SQL select returns an empty set asynchronously?

Is this possible easily? It seems the handleResult method is only executed if the result isn't the empty set.
A thought I had was to have handleResult and handleCompletion be member functions of an object and have handleResult update a member variable that handleCompletion can check. If the variable is set, not empty, if variable unset, empty and can act accordingly.
seems to be overly complicated and hoping there's a better solution?
to sketch out a solution (the thought i had above) (edit2: per comment I made below)
function sql() {
this.results = false;
var me = this;
this.handleResult = function(aResultSet) {
for (var row = aResultSet.getNextRow(); row; row = aResultSet.getNextRow()) {
me.results = true;
var value = row.getResultByName("name");
}
};
this.handleError = function(aError) {
.... //deal with error
};
this.handleCompletion = function(aReason) {
if (me.results) {
....//results
} else {
....//no results
}
if (aReason != Components.interfaces.mozIStorageStatementCallback.REASON_FINISHED) {
....//handle these
};
};
s = new sql();
statement.executeAsync({
handleResult: s.handleResult,
handleError: s.handleError,
handleCompletion: s.handleCompletion
});
is this considered a good way to solve this problem?
edit1: this doesn't behave in the manner I'd expect (it works, but not 100% sure why). i.e. the this.results variable is undefined (not false), if handleResult never runs. So it appers as if handleResult and handleCompletion are operating on a different set of variables than I'd expect.
any help to understand what I'm doing wrong would be appreciated.

Queuing system for actionscript

Is there an actionscript library providing a queuing system?
This system would have to allow me to pass the object, the function I want to invoke on it and the arguments, something like:
Queue.push(Object, function_to_invoke, array_of_arguments)
Alternatively, is it possible to (de-)serialize a function call? How would I evaluate the 'function_to_invoke' with the given arguments?
Thanks in advance for your help.
There's no specific queue or stack type data structure available in ActionScript 3.0 but you may be able to find a library (CasaLib perhaps) that provides something along those lines.
The following snippet should work for you but you should be aware that since it references the function name by string, you won't get any helpful compiler errors if the reference is incorrect.
The example makes use of the rest parameter which allows you to specify an array of arbitrary length as the arguments for your method.
function test(... args):void
{
trace(args);
}
var queue:Array = [];
queue.push({target: this, func: "test", args: [1, 2, "hello world"] });
queue.push({target: this, func: "test", args: ["apple", "pear", "hello world"] });
for (var i:int = 0; i < queue.length; i ++)
{
var queued:Object = queue[i];
queued.target[queued.func].apply(null, queued.args);
}
Sure, that works similar to JavaScript
const name:String = 'addChild'
, container:Sprite = new Sprite()
, method:Function = container.hasOwnProperty(name) ? container[name] : null
, child:Sprite = new Sprite();
if (method)
method.apply(this, [child]);
So a query method could look like:
function queryFor(name:String, scope:*, args:Array = null):void
{
const method:Function = scope && name && scope.hasOwnProperty(name) ? scope[name] : null
if (method)
method.apply(this, args);
}