DART Editor, "Dead code" statement - dart

I'm trying to toggle my menu upon clicking menuicon (defined as #lines) in my code below.
In execution, everything is fine, I mean, once I run the code in DARTIUM it works as I want, the menu is toggled upon the click.
but in Dart editor, I got the error msg in the attached pic, am I doing something wrong in my code?
void main() {
....
var menuToggle =querySelector('#lines')
..onClick.listen((e)=>fonixMenu.hidden=true ? !fonixMenu.hidden : false);
....
}

I think it's telling you that the false in your code will never be reached, because the true causes the first part of the expression to be returned.
You can simplify it to:
onClick.listen((e) => fonixMenu.hidden = !fonixMenu.hidden);

I think what you actually wanted to do was
void main() {
....
var menuToggle =querySelector('#lines')
..onClick.listen((e) => fonixMenu.hidden = fonixMenu.hidden == true ? = false : fonixMenu.hidden = true);
// ^ 2nd =
....
}
but Danny's solution is more elegant when you ensure that fonixMenu.hidden is never null because
var x = null;
var Y = !x
causes an exception:
type 'Null' is not a subtype of type 'bool' of 'boolean expression'.
A simple null-safe variant
var menuToggle =querySelector('#lines')
..onClick.listen((e) => fonixMenu.hidden = fonixMenu.hidden == true ? false : true);

Related

how to convert initialization code that requires an action to F#

I have the following C# code:
var client = new RestClient(url);
client.ConfigureWebRequest((r) =>
{
r.ServicePoint.Expect100Continue = false;
r.KeepAlive = true;
});
in F#, after I initialize the rest client, how can I structure the ConfigureWebRequest call? I don't know the syntax to use.
client.ConfigureWebRequest(fun r ->
r.ServicePoint.Expect100Continue <- false
r.KeepAlive <- true
)

Cannot read property 'length' of null when using MatPaginator

I keep on getting this error:
core.js:1542 ERROR TypeError: Cannot read property 'length' of null
at MatTableDataSource.push../node_modules/#angular/material/esm5/table.es5.js.MatTableDataSource._filterData (table.es5.js:702)
at MapSubscriber.project (table.es5.js:657)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapSubscriber._next (map.js:35)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
at CombineLatestSubscriber.push../node_modules/rxjs/_esm5/internal/observable/combineLatest.js.CombineLatestSubscriber.notifyNext (combineLatest.js:83)
at InnerSubscriber.push../node_modules/rxjs/_esm5/internal/InnerSubscriber.js.InnerSubscriber._next (InnerSubscriber.js:15)
at InnerSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
at BehaviorSubject.push../node_modules/rxjs/_esm5/internal/BehaviorSubject.js.BehaviorSubject._subscribe (BehaviorSubject.js:22)
at BehaviorSubject.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (Observable.js:42)
at BehaviorSubject.push../node_modules/rxjs/_esm5/internal/Subject.js.Subject._trySubscribe (Subject.js:89)
I get my data from a service that gets from a database. It functions just fine. What I mean is the functionality is right. I can do the paging it's just that I get this error in the inspector. Please see my code below:
ngOnInit() {
if (this.genParams.buildingId === null || this.genParams.buildingId === undefined) {
this.router.navigate(['/main/viewproperties']);
}
this.buildingId = this.genParams.buildingId;
this.getUnits();
}
public getUnits() {
this.isLoading = true;
this.unitService.newGetUnits(this.buildingId)
.subscribe((data: any) => {
this.ELEMENT_DATA = data;
this.dataSource = new MatTableDataSource(this.ELEMENT_DATA);
this.dataSource.paginator = this.paginator;
this.isLoading = false;
console.log(this.ELEMENT_DATA);
}, err => {
console.log(err);
});
}
This is in my html:
<mat-paginator [pageSizeOptions]="[1, 5, 10, 20]" showFirstLastButtons></mat-paginator>
I would really appreciate your help.
I suspect that this is a scope issue. Try adding this to the class, not a function. You refer to this.datasource but setting it up as new in the function so I assume you just declare the var in the class. I've seen this error many times and it is when my dataSource is not receiving data but you seem to indicate that your table is functioning with data.
Stackblitz example
// For data table operations.
private dataSource = new MatTableDataSource();
private dataLength: number;

Why does the error method return an error?

I want to validate input corresponding to the following grammar snippet:
Declaration:
name = ID "=" brCon=BracketContent
;
BracketContent:
decCon=DecContent (comp+=COMPARATOR content+=DecContent)*
;
DecContent:
(neg=("!"|"not"))? singleContent=VarContent (op+=OPERATOR nextCon+=VarContent)*
;
My validation looks like that:
#Check
def checkNoCycleInHierarchy(Declaration dec) {
if(dec.decCon.singleContent.reference == null) {
return
}
var names = newArrayList
var con = dec.decCon.singleContent
while(con.reference != null) {
con = getThatReference(con).singleContent
if(names.contains(getParentName(con))) {
val errorMsg = "Cycle in hierarchy!"
error(errorMsg,
SQFPackage.eINSTANCE.bracketContent_DecCon,
CYCLE_IN_HIERARCHY)
return
}
names.add(getParentName(con))
}
}
But when I test this validation with a testCaseit returns me an error message:
Expected ERROR 'raven.sqf.CycleInHierarchy' on Declaration at [-1:-1] but got
ERROR (org.eclipse.emf.ecore.impl.EClassImpl#5a7fe64f (name: Declaration) (instanceClassName: null) (abstract: false, interface: false).0) 'Error executing EValidator', offset null, length null
ERROR (org.eclipse.emf.ecore.impl.EClassImpl#5a7fe64f (name: Declaration) (instanceClassName: null) (abstract: false, interface: false).0) 'Error executing EValidator', offset null, length null
I just can't figure out what's wrong with it so I hope that someone of you might have an idea.
Greetings Krzmbrzl
You test utility tells you that the validator did not produce the expected validation error ("CycleInHierarchy").
Instead, the validator produced the error "Error executing EValidator".
Which means an exception has been thrown when your validator was executed.
It turned out it was an internal error...I'm still not exactly sure what went wrong but I have rewritten my validation method and now it works as expected.
Now the method looks like this:
enter code here#Check
def checkNoCycleInHierarchy(Declaration dec) {
if(dec.varContent.reference == null) {
//proceed only if there is a reference
return
}
var content = dec.varContent
var names = newArrayList
while(content.reference != null && !names.contains(getParentName(content))) {
names.add(getParentName(content))
content = content.reference.varContent
if(names.contains(getParentName(content))) {
val errorMsg = "Cycle in hierarchy!"
error(errorMsg,
SQFPackage.eINSTANCE.declaration_BrCon,
CYCLE_IN_HIERARCHY)
return
}
}
}
I have the suspicion that there was a problem with the usage of my "getThatReference" in this case.
Greeting Krzmbrzl

What cause of 'formal parameter name expected' occured in this case?

I run the code below and I got an error without any stack trace.
My code:
typedef Check<T>(T value, [onError(T value)]);
main () {
List<Check> checks = [
(str) => str != null,
(str) => !str.isEmpty
];
Check<String> doCheck = (String value, [onError(String)]) {
checks.forEach((Check check) {
if (?onError) {
check(value, onError);
} else {
check(value);
}
});
};
doCheck("10");
}
And, the error I got.
file:///..()../sample.dart': Error: line 11 pos 12: formal parameter name expected
if (?onError) {
I want to get onError as an optional parameter in doCheck function, and pass this parameter to other functions in checks.
I confirmed to forward an optional parameter to 'one' function...
Is this one of restrictions to optional parameters?
I would say it is a bug (see issue 8007). To work around it, you have to use a temporary variable :
typedef Check<T>(T value, [onError(T value)]);
main () {
List<Check> checks = [
(str) => str != null,
(str) => !str.isEmpty
];
Check<String> doCheck = (String value, [onError(String)]) {
final isOnErrorPresent = ?onError;
checks.forEach((Check check) {
if (isOnErrorPresent) {
check(value, onError);
} else {
check(value);
}
});
};
doCheck("10");
}

how to use validationResover

Like shown here I want to use the validationResolver to dynamically validate user inputs in my App. Therefore I want to proove, if a condition is true in my controller. If the condition is true, I want to validate with an own validator.
For that I tried that:
public function createAction(Object $newObject) {
$TS = $newObject->getSomeProperty();
$ABT = $newObject->getSomeOtherProperty();
if ($TS === 'specialvalue') {
$validatorResolver->createValidator('Your.Package:Foo'));
}
But I get (of course) an 500-exception:
#1: Notice: Undefined variable: validatorResolver in /var/www...
Please give me a hint how to use the $validatorResolver.
I did it now this way:
public function createAction(Object $newObject) {
$TS = $newObject->getSomeProperty();
$ABT = $newObject->getSomeOtherProperty();
if ($ABT === 'specialvalue') {
$validatorResolver = new \TYPO3\Flow\Validation\ValidatorResolver();
$customValidator = $validatorResolver->createValidator('Your.Package:Foo');
$result = $customValidator->validate($TS);
if ($result->hasErrors()) {
$this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error('Here you can type in the error message!'));
$this->errorAction()->forwardToReferringRequest();
}
}
....
....
}

Resources