branch.io Share Sheet message - javascript

This is a function im calling on Ionic
regularShare(){
// only canonicalIdentifier is required
var properties = {
canonicalIdentifier: 'content/' + this.itemId
}
// create a branchUniversalObj variable to reference with other Branch methods
var branchUniversalObj = null
Branch.createBranchUniversalObject(properties).then(function (res) {
branchUniversalObj = res
// optional fields
var analytics = {
}
// optional fields
var properties = {
}
var message = 'Check out this link'
// optional listeners (must be called before showShareSheet)
branchUniversalObj.onShareSheetLaunched(function (res) {
// android only
console.log(res)
})
branchUniversalObj.onShareSheetDismissed(function (res) {
console.log(res)
})
branchUniversalObj.onLinkShareResponse(function (res) {
console.log(res)
})
branchUniversalObj.onChannelSelected(function (res) {
// android only
console.log(res)
})
// share sheet
branchUniversalObj.showShareSheet(analytics, properties, message)
});
}
When I change var message to the following, it errors out. Error below.
var message = "Check out " + this.itemDetails.name + " (" + this.itemDetails.subcat+ ") in " + this.itemDetails.location + "."+ " Address: " + this.itemDetails.address+ ". Contact: " + this.itemDetails.phone
ERROR: ERROR Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'this.itemDetails')
However, in all my other functions it seems to run fine using the same message and variables.
Just trying to place the value of the variables within the message instead of the default message: Check out this link
Thanks :)

To get it working, I had to change the line from
Branch.createBranchUniversalObject(properties).then(function (res) {
To
Branch.createBranchUniversalObject(properties).then((res) => {

Related

variable is not getting defined even though the code works somwhere else

so i am building a game in three js and trying to make it multiplayer throught socket.io so i am loading all of my characters into an array called players on my server side
and then i pass it to each client when they connect like so
socket.on('addPlayer', function(username) {
players.push(username)
console.log(username + " joined")
console.log("online Users " + players)
socket.broadcast.emit('syncPlayers', players)
socket.emit('syncPlayers', players)
})
and on my client syncPlayers looks like this
socket.on('syncPlayers', function(players) {
players.forEach(function(value) {
if (value == username) {
console.log("not adding " + value + " thats you ")
loadPlayerdata(username)
} else {
console.log("player Online " + value);
newplayer = value;
loadPlayerdata(newplayer)
addPlayer(newplayer)
}
});
})
then it calls this wich sends the server data
function loadPlayerdata(playerName) {
console.log(playerName)
console.log("phase1")
socket.emit('loadPlayerdata', playerName)
}
then this is called and it retrieved the player name and the data of the players location this is were my problem lies
socket.on('loadPlayerdata', function(data, username) {
toMove = threeObjects[username + "Char"]
if (data == "null" || "") {
console.log(username + " is new")
} else {
console.log(username + " Exists")
console.log(toMove)
toMove.position.set(world.spawnPointx, world.spawnPointy, world.spawnPointz)
}
i keep getting Uncaught TypeError: Cannot read property 'position' of undefined
even though i can use this
function addPlayer(playerName) {
var charObjectName = playerName + "Char"
var threeObject = models.tent1.mesh.clone();
scene.add(threeObject)
//threeObject.position.set(world.spawnPointx, world.spawnPointy, world.spawnPointz)
// set reference
threeObjects[charObjectName] = threeObject;
}
btw i have an object
var threeObjects = {};
can someone please explain why it wont work and how to fix it
You can read this answer to understand the difference between dot and brackets notation.
You are getting error because, tomove seems to be undefined and dot notation will throw error if any new user joins and if the object is empty.
Check if this helps. This will assign the object key as username and position as an value which will be array like this,
{"usernamechar": {"position": [x,y,z]}}
socket.on('loadPlayerdata', function(data, username) {
if (data == "null" || "") {
console.log(username + " is new")
} else {
console.log(username + " Exists")
threeObjects[username + "Char"]["position"] = [world.spawnPointx, world.spawnPointy, world.spawnPointz]
}
}

Cannot read property 'finally' of undefined

I can't figure out why I'm getting an
Cannot read property 'finally' of undefined error here..
$scope.saveToDos = function(){
console.log("Save to do was pressed.")
var filteredTodos = $scope.todos.filter(function(todo){
if(todo.edited){
return todo
}
})
console.log("There are " + filteredTodos.length + " edited todos")
dataService.saveToDos(filteredTodos)
.finally($scope.resetTodoState())
}
It errors out on the finally line and I'm not sure why.
The issue can be reproduced cloning Git repo
https://github.com/Velua/To-Do-List
this.saveToDos = function(todos){
var queue = [];
todos.forEach(function(todo){
var request;
if(!todo._id){
request = $http.post('/api/todos', todo);
} else{
request = $http.put('/api/todos/' + todo._id, todo).then(function(result){
todo = result.data.todo;
return todo
})
}
queue.push(request);
})
$q.all(queue).then(function(results){
console.log("I saved " + todos.length + " todos!");
})
}
Thanks!
You aren't returning anything from saveToDos(), so the return value is by default undefined.
You probably wanted to return $q.all(...

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

javascript post not doing function but load url

I am creating Stratego.
(the error is farther down)
so i am creating the map when the page is loadet whit:
turn = true;
komboType = "2kombo";
GameOpsetning = [];
GameOpsetningEnemy = [];
$(document).ready(function() {
createmap();
}
and then i do some console log to make sure it works..
function createmap () {
if (!GameStarted) {
console.log("GameOpsetning" + GameOpsetning);
if(GetSetup(Gameid)){
console.log("GameOpsetning1" + GameOpsetning);
}
else
{
console.log("GetSetup : error");
}
and here the error comes, it will open the file "game.php" whit no error. but it will not do eny thing in side the post/funcion. It will not do the alert or the if or console.log?
function GetSetup (Gameid) {
console.log("GameOpsetning3: " + GameOpsetning);
if ($.post("game.php", { gameid: Gameid }, function(data) {
alert(data);
var data2 = JSON.stringify(data);
alert(data2);
//var json = $.parseJSON(data);
if (data2.status2 && data2.status2 != "false") {
console.log("data.game: " + JSON.stringify(data.game));
GameOpsetning = JSON.stringify(data.game);
GameOpsetningEnemy = JSON.stringify(data.enemygame);
komboType = data.type;
turn = data.turn;
console.log("GameOpsetning5: " + GameOpsetning);
return true;
}
else
{
console.log("error: ");
return false;
}
})){
console.log("post: done");
}else{
console.log("post: error");
}
console.log("GameOpsetning4: " + GameOpsetning);
}
the console output:
GameOpsetning
GameOpsetning3:
post: done
GameOpsetning4:
GetSetup : error
there is no console errors and the page is return JSON
and it have try ed to do like:
console.log("GameOpsetning" + GameOpsetning);
GetSetup(Gameid);
console.log("GameOpsetning1" + GameOpsetning);
if (CheckGame()) {
then the console log is:
GameOpsetning
GameOpsetning1
GameOpsetning3:
post: done
GameOpsetning4:
GetSetup : error
Sorry for my bad English.
You're testing if($.post("game.php",... What is the result of this if test? Always true. Because anything that is not false, 0 or undefined is true. You're not testing the result of an ajax call, you're testing an ajax call (a function).
Same with if(GetSetup(Gameid)). GetSetup(Gameid) returns : console.log("GameOpsetning4: " + GameOpsetning). if(GetSetup(Gameid)) result is undefined, which explains the GetSetup : error output.
Type this in your console : if(console.log('test')) alert("yay") : it won't alert "yay", it will just log 'test' and return undefined. This is your if(GetSetup(Gameid)).
Same way, if you type if($.post("game.php")) alert('yay'), it will alert yay, because the test is always true, whatever the result of the $.post.

TypeError: Object Is Not A Function (JavaScript Chrome Storage Sync)

This is for accessing preferences saved in chrome.storage.sync using JavaScript for a Chrome Extension.
Code:
chrome.storage.sync.get('allWeights', function(obj) {
allWeights = obj.allWeights();
chrome.storage.sync.get('allIDs', function(obj2) {
allIDs = obj2.allIDs();
alert("ALL WEIGHTS: " + allWeights);
alert("ALL IDS: " + allIDs);
});
});
Error:
Error in response to storage.get: TypeError: object is not a function
at HTMLDocument.restore_options
And the error is pointing to the first line (chrome.storage.sync.get('allWeights').
What is causing this error and how can I fix it?
EDIT: This works
chrome.storage.sync.get(null, function(items) {
allWeights = items.allWeights;
allIDs = items.allIDs;
alert("ALL WEIGHTS: " + allWeights);
alert("ALL IDS: " + allIDs);
});
I had to change items.allWeights() to items.allWeights.
Apparently you can't access an object property with ()

Categories

Resources