Unhandled expression at line : - javascript

So i am playing around with Babylon. In a createScene function I am also loading the AssetManager.
Whenever i add a task, it will throw errors: unhandled expression 1 for every line of my HTML document.
This also happens, if I ignore my assetManager and put in SceneLoader.ImportMesh instead.
I really dont know what to do anymore.
Thats my assetManager:
function assetManager() {
var assetsManager = new BABYLON.AssetsManager(scene);
var meshTask = assetsManager.addMeshTask("baum", "", "assets/", "carAcura.obj");
meshTask.onSuccess = function (task) {
task.loadedMeshes[0].position = BABYLON.Vector3.Zero();
engine.loadingUIText = "Loaded asset " + task.loadedMeshes[0].name;
console.log(task.loadedMeshes[0].name);
}
assetsManager.onTaskError = function (task) {
console.log("error on Loading" + task.name);
}
assetsManager.load();
assetsManager.onFinish = function (tasks) {
console.log("done");
engine.runRenderLoop(function () {
if (engine.webGLVersion === 1) {
pixiRenderer.reset();
}
scene.render();
engine.wipeCaches(true);
pixiRenderer.reset();
pixiRenderer.render(stage);
divFps.innerHTML = engine.getFps().toFixed() + " FPS";
//loop();
});
};
};

Related

How can I fix error "_helpers.pageUrl is not a function:" in my KeystoneJS project?

I have guide website and I want to add some tours there.
I created two models: Tour.js and TourCategory.js (similar to Post.js and PostCategory.js). Then I had to create two routes: tours.js and tour.js (also similar for posts). When I was adding helpers I caught error: _helpers.pageUrl is not a function
How can I fix it?
I have tried to find if anybody has the same problem but found nothing.
I have no idea how to fix it because I did not change anything in my code (helpers/index.js) before adding my new helpers.
My helpers/index.js fragment:
_helpers.tourUrl = function (categorySlug, tourSlug, options) {
return ('/tours/' + categorySlug + tourSlug);
};
_helpers.categoryUrl = function (categorySlug, options) {
return ('/tours/' + categorySlug);
};
_helpers.paginationNavigation = function (pages, currentPage, totalPages, options) {
var html = '';
_.each(pages, function (page, ctr) {
var pageText = page;
var isActivePage = ((page === currentPage) ? true : false);
var liClass = ((isActivePage) ? ' class="active"' : '');
if (page === '...') {
page = ((ctr) ? totalPages : 1);
}
var pageUrl = _helpers.pageUrl(page);
html += '<li' + liClass + '>' + linkTemplate({ url: pageUrl, text: pageText }) + '</li>\n';
});
return html;
}
I expected that page will load without any errors.
Because of in your helper file you don't make any function with the name pageUrl and try to access in another function_helpers.pageUrl().
You need to add a function (if not exist ) with the name pageUrl like this
const _helpers = {};
_helpers.pageUrl = (input) => {
try {
// ... Your business logic
return true; // It's up to you
} catch (err) {
console.log(err);
throw err;
}
};
module.exports = _helpers

Nativescript bind value inside image-picker function

I am using image-picker plugin. I can open images gallery and select single or multiple images.
My problem is how to bind the path of the image to the xml image src?! It doesn't work inside getImage() function.
xml:
<Image class="imageSource" src="{{ thumb }}" stretch="none" />
typescript:
import { Observable } from 'data/observable';
import * as imagepicker from "nativescript-imagepicker";
var counter = 0;
var fs = require('file-system');
export class AssistenceViewModel extends Observable {
thumb:any;
public addImage(){
dialogs.action({
message: "Opções",
cancelButtonText: "Cancelar",
actions: ["Câmera", "Galeria"]
}).then(result => {
console.log("Dialog result: " + result);
if(result == "Câmera"){
//Do action1
console.log("Abrir camera");
}else if(result == "Galeria"){
console.log("Abrir galeria");
let context = imagepicker.create({
mode: "single"
});
context.authorize().then(function() {
return context.present();
}).then(function(selection) {
selection.forEach(function(selected){
selected.getImage().then(function(imagesource){
var localPath = null;
if(platformModule.device.os === "Android"){
localPath = selected.android;
console.log("localPath android: " +localPath);
}else {
// selected_item.ios for iOS is PHAsset and not path - so we are creating own path
let folder = fs.knownFolders.documents();
let path = fs.path.join(folder.path, "Test" + counter + ".png");
let saved = imagesource.saveToFile(path, "png");
localPath = path;
console.log("localPath iOS: " +localPath);
}
if(localPath){
this.thumb = localPath // this is not working
console.log("thumb: "+this.thumb); // this is not working
}
});
});
}).catch(function(e) {
console.log(e);
});
}
});
}
}
The result for console.log("localPath android: " +localPath);
localPath android: /storage/emulated/0/DCIM/Camera/IMG_20171213_224917038.jpg
but I cannot get any log for this.thumb.
You should either use TS arrow functions to preserve the context of this of "cache the meaning of this"
e.g. for arrow functions
// more code above this line
.then(() => {
return context.present();
}).then((selection) => {
selection.forEach((selected) => {
selected.getImage().then((imagesource) => {
Or that = this; pattern
var that = this;
// ... your code in the promises follows
that.thumb = newValue;

ClassNotFoundException in NativeScript using .extend()

I am trying to extend GoogleApiClient.ConnectionCallbacks(), but keep getting an error
`java.lang.RuntimeException: Unable to start activity
ComponentInfo{org.nativescript.sampleGroceries/com.tns.NativeScriptActivity}:
com.tns.NativeScriptException: Calling js method onCreate failed
Error calling module function
Error: java.lang.ClassNotFoundException:
com.google.android.gms.common.api.GoogleApiClient_ConnectionCallbacks
java.lang.Class.classForName(Native Method)
java.lang.Class.forName(Class.java:324)
java.lang.Class.forName(Class.java:285)
com.tns.DexFactory.generateDex(DexFactory.java:262)
com.tns.DexFactory.resolveClass(DexFactory.java:120)
com.tns.ClassResolver.resolveClass(ClassResolver.java:45)
`
My corresponding code is
var GoogleApiClient = com.google.android.gms.common.api.GoogleApiClient;
var myConnectionCallbacks = GoogleApiClient.ConnectionCallbacks.extend({
onConnected: function(connectionHint){
var MessageListener = MessageListener.extend({
onFound: function(message){
Log.d("MESSAGE", "Found message :) ");
},
onLost: function(message){
Log.d("MESSAGE", "Lost message :( ");
}
});
var mMessageListener = new MessageListener();
},
onConnectionSuspended: function(){}
});
var MessagesOptionsBuilder = new com.google.android.gms.nearby.messages.MessagesOptions.Builder().setPermissions(NearbyPermissions.BLE).build();
var test = new GoogleApiClient.Builder(context).addApi(Nearby.MESSAGES_API, MessagesOptionsBuilder);
test.addConnectionCallbacks(new myConnectionCallbacks(this));
Maybe I misunderstood the Docs?
https://docs.nativescript.org/runtimes/android/generator/extend-class-interface
Edit: Why is there an underscore in the error log after GoogleApiClient?
Any suggestions what I do wrong?
The problem here is your are trying to extend an interface which is wrong . More info -> https://docs.nativescript.org/runtimes/android/generator/extend-class-interface#interfaces
var MessagesOptionsBuilder = new com.google.android.gms.nearby.messages.MessagesOptions.Builder().setPermissions(NearbyPermissions.BLE).build();
var test = new GoogleApiClient.Builder(context).addApi(Nearby.MESSAGES_API, MessagesOptionsBuilder);
test.addConnectionCallbacks(new com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks({
onConnected: function (connectionHint) {
var MessageListener = MessageListener.extend({
onFound: function (message) {
console.log(Found message :) ");
},
onLost: function (message) {
console.log("Lost message :( ");
}
});
var mMessageListener = new MessageListener();
},
onConnectionSuspended: function () { }
}));
and just incase the MessageListener is an interface the just remove the .extend
var MessagesOptionsBuilder = new com.google.android.gms.nearby.messages.MessagesOptions.Builder().setPermissions(NearbyPermissions.BLE).build();
var test = new GoogleApiClient.Builder(context).addApi(Nearby.MESSAGES_API, MessagesOptionsBuilder);
test.addConnectionCallbacks(new com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks({
onConnected: function (connectionHint) {
new MessageListener({
onFound: function (message) {
console.log(Found message :) ");
},
onLost: function (message) {
console.log("Lost message :( ");
}
});
},
onConnectionSuspended: function () { }
}));

Callback generates "TypeError: this is undefined" in Angular2/Firebase

I'm trying to understand what is gong on here and why I'm getting an error if I call a function a certain way and not getting the error when i call the function a different way. Here is the way that produces the error first:
player.service.ts file
in the #Injectable i have
private roomsRef: Firebase;
constructor() {
this.roomsRef = new Firebase("https://xxx.firebaseio.com/rooms");
}
postGameActions(roomId: string) {
console.log("post game actions start on " + roomId);
//error on below 'this'
this.roomsRef.child(roomId).child("board").once("value", snap => {
let board = snap.val();
//do stuff with 'board' object
});
}
room.component.ts file
activateTimer(roomId: string, roomName: string, callback) {
var timer = setInterval(redirectTimer, 1000);
var seconds: number = 5;
var timerHtml = document.getElementById("divRedirectTimer" + roomName);
timerHtml.innerHTML = "[" + seconds + "]";
function redirectTimer() {
timerHtml.innerHTML = "[" + (seconds--) + "]";
if(seconds === 0) {
clearInterval(timer);
callback(roomId);
}
};
}
call non-working version like this
activateTimer(room.id, room.name, _playerService.postGameActions)
Error:
EXCEPTION: TypeError: this is undefined
Working version
Works fine when like this but no use of setInterval() since activateTimer just calls the service method
room.component.ts file
activateTimer(roomId: string, roomName: string) {
var timer = setInterval(redirectTimer, 1000);
var seconds: number = 5;
var timerHtml = document.getElementById("divRedirectTimer" + roomName);
timerHtml.innerHTML = "[" + seconds + "]";
function redirectTimer() {
timerHtml.innerHTML = "[" + (seconds--) + "]";
if(seconds === 0) {
clearInterval(timer);
}
}
this._playerService.postGameActions(roomId);
call working version like this
activateTimer(room.id, room.name)
Why is the 'this' undefined when i call postGameActions as a callback? I'm sure I'm missing something simple here
You need to wrap the call into an arrow function:
activateTimer(room.id, room.name, () => {
_playerService.postGameActions();
});
The problem in your code is that you reference directly a function so you lose the object it will be executed on.
Another way would be to use the bind method:
activateTimer(room.id, room.name, _playerService.postGameActions.bind(_playerService);

Protractor - Error: Index out of bound exception while using the same function for the second time

I have the following function which selects a category from a list of available categories. This function works fine in my first test. But the same function with a different valid category name in my second test fails with the following error.
Error: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator By.cssSelector(".grid-view-builder__category")
this.categoryElements = element.all(by.css('.grid-view-builder__category'));
this.selectCategory = function (categoryName) {
var filteredCategories = this.categoryElements.filter(function (category) {
return category.getText().then(function (text) {
log.info(text);
return text === categoryName;
})
})
filteredCategories.first().click().then(function () {
log.info("Select Category: " + categoryName);
}).then(null, function (err) {
log.error("Category: " + categoryName + " Not Found !!" + err);
});
}
Spec File
var columnSelect = require('pages/grid/columns/columnselector-page')()
it('Add Publisher ID Column to the Grid & Verify', function () {
var columnCountBefore = columnSelect.getColumnCount();
columnSelect.openColumnSelector();
columnSelect.selectCategory('Advanced');
columnSelect.selectColumn('Publisher ID');
columnSelect.apply();
var columnCountAfter = columnSelect.getColumnCount();
expect(columnCountAfter).toBeGreaterThan(columnCountBefore);
});
The problem might be in the way you are defining and using Page Objects. Here is a quick solution to try - if this would help, we'll discuss on why that is happening.
Make the categoryElements a function instead of being a property:
this.getCategoryElements = function () {
return element.all(by.css('.grid-view-builder__category'));
};
this.selectCategory = function (categoryName) {
var filteredCategories = this.getCategoryElements().filter(function (category) {
return category.getText().then(function (text) {
log.info(text);
return text === categoryName;
})
})
filteredCategories.first().click().then(function () {
log.info("Select Category: " + categoryName);
}).then(null, function (err) {
log.error("Category: " + categoryName + " Not Found !!" + err);
});
}
Or, this could be a "timing issue" - let's add an Explicit Wait via browser.wait() to wait for at least a single category to be present:
var EC = protractor.ExpectedConditions;
var category = element(by.css('.grid-view-builder__category'));
browser.wait(EC.presenceOf(category), 5000);
It looks like this has nothing to do with the code posted here, only that the css selector you're using is not finding any elements

Categories

Resources