Passing operator to setInterval() actionscript - actionscript-3

I would like assign setInterval() to pass an operator as an argument by following the Answer of LiraNuna
function actualFunction(passedValue:Number, compareFunction:Function) {
/* ... */
if(compareFunction(passedValue, staticValue)) {
/* ... Do something ... */
}
/* ... */
}
actualFunction(6, function(x:Number, y:Number) {
return x > y;
});
from this link pass < or > operator into function as parameter?
But I don't seem to know how to do it since only the function name is called when initiating setInterva().
Typical initiation:
function actualFunction(passedValue:Number, compareFunction:Function) {
/* ... */
if(compareFunction(passedValue, staticValue)) {
/* ... Do something ... */
}
/* ... */
}
setInterval(actualFunction,10)
Now, I want to assign
actualFunction(6, function(x:Number, y:Number) {
return x > y;
});
within setInterval(), how would I do it?

Try this (not tested) :
setInterval(actualFunction, 10, 6, function(x:Number, y:Number){return x > y});
Read this for more information : http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#setInterval()
Hope this helps.

Related

Checking for a maximum level of indentation in Checkstyle

I want to ensure that my code does not exceed 5 levels of indentation, like so:
class Foo { // 0
void bar() { // 1
if () { // 2
if () { // 3
if () { // 4
if () { // 5
if () { // 6 - error
}
}
}
}
}
}
}
Looking through the Checkstyle documentation, I couldn't find a rule that specifically implements this. Does such a rule exist, or do I have to look into custom rules?
There is an issue still in "Open" state about this feature: https://github.com/checkstyle/checkstyle/issues/5487
Not exactly what you need, but you can achieve something similar using the NestedForDepth, NestedIfDepth and NestedTryDepth checks.

Ngx-formly check for focus in expressionProperties

I am using ngx-formly v: 5.5.10. I try to check if field is focused in the expressionProperties.
This is necessary for changing the value based on focus. Something like this:
expressionProperties: {
'model.testField': (m) => {
if (m.testField.value && testField.focus=true) {
return x;
} else {
return y;
}
}
}
Is there a formly built-in solution for checking focus in the expressionProperties?
Thanks for any help!
The field instance is passed as a third argument of the expression callback:
expressionProperties: {
'model.testField': (m, formState, field) => {
if (m.testField.value && field.focus === true) {
return x;
} else {
return y;
}
}
}

Istanbul how to ignore default value branch for ES6 (babel compiles to ES5)

In ES5 we can write like this:
function(a){
/* istanbul ignore next */
a = a || 123;
}
how to ignore In ES6?
function(a = 123 ){
}
I tried this:
function(/* istanbul ignore next */a = 123 ){
}
but it's not working.
This works for me:
function(
/* istanbul ignore next */
a = 123
){
}
When using TypeScript, this was a bit harder to solve since the types must match. I was able to get it to work by passing in undefined for each parameter. For example...
function testMe(a:SomeType = { foo: 'bar' }, b:AnotherType = { bar: 'baz'}) {
return a * b;
}
describe('Branch Coverage', () => {
it('should pass branch coverage', () => {
expect(testMe(undefined, undefined);
});
});

Why don't Sass functions work outside selectors?

I have an example.scss file. When it is imported (parsed), I would like to push a value to a map.
// Declare selectors
register(example);
Prior to its import, the following has already been imported:
$example-map: (
);
#function register($key){
$pointless: map-set($example-map, $key, true); // Have to assign to a variable
#return true; // Have to return something
}
This is invalid as it appears that functions cannot be called outside of selectors. Why is this?
Codepen here
You can use a mixin instead. Sure it's a little more to type but it should work.
Here's my quick test:
$register: ();
#mixin register ($key) {
#if not index($register, $key) {
$register: append($register, $key);
}
}
#include register(foo);
#include register(bar);
#include register(bar);
#include register(baz);
body {
content: $register;
}
Then you can test if it's registed just using index.
#if index($register, foo) {
.foo {
color: red;
}
}
Here's a small demo:
Sassmeister: http://sassmeister.com/gist/6069ebaba50d29052eeb

Jinja2 automatic creation of prefix whitespace

In StringTemplate - which I've used in some projects to emit C code - whitespace prefixes are automatically added in the output lines:
PrintCFunction(linesGlobal, linesLocal) ::= <<
void foo() {
if (someRuntimeFlag) {
<linesGlobal>
if (anotherRuntimeFlag) {
<linesLocal>
}
}
}
>>
When this template is rendered in StringTemplate, the whitespace
prefixing the multilined linesGlobal and linesLocal strings,
is copied for all the lines emitted. The generated C code is
e.g.:
void foo() {
if (someRuntimeFlag) {
int i;
i=1; // <=== whitespace prefix copied in 2nd
i++; // <=== and 3rd line
if (anotherRuntimeFlag) {
int j=i;
j++; // <=== ditto
}
}
}
I am new to Jinja2 - and tried to replicate this, to see if I can use Python/Jinja2 to do the same thing:
#!/usr/bin/env python
from jinja2 import Template
linesGlobal='\n'.join(['int i;', 'i=1;'])
linesLocal='\n'.join(['int j=i;', 'j++;'])
tmpl = Template(u'''\
void foo() {
if (someRuntimeFlag) {
{{linesGlobal}}
if (anotherRuntimeFlag) {
{{linesLocal}}
}
}
}
''')
print tmpl.render(
linesGlobal=linesGlobal,
linesLocal=linesLocal)
...but saw it produce this:
void foo() {
if (someRuntimeFlag) {
int i;
i=1;
if (anotherRuntimeFlag) {
int j=i;
j++;
}
}
}
...which is not what I want.
I managed to make the output emit proper whitespace prefixes with this:
...
if (someRuntimeFlag) {
{{linesGlobal|indent(8)}}
if (anotherRuntimeFlag) {
{{linesLocal|indent(12)}}
}
}
...but this is arguably bad, since I need to manually count whitespace
for every string I emit...
Surely Jinja2 offers a better way that I am missing?
There's no answer (yet), because quite simply, Jinja2 doesn't support this functionality.
There is, however, an open ticket for this feature - if you care about it, join the discussion there.