Vue - removing all spaces from a string from Firestore database - vuejs2

I am still learning Vue. I know how to remove all spaces from a string using Javascript, such as:
var str = " a b c d e f g ";
var newStr = str.replace(/\s+/g, '');
I can't figure out how to implement this in Vue.
I would like to take a string from my Firestore database, say a field called "title1", with a value of "This is my string" and remove all spaces so it says "Thisismystring". Then I want to be able to use that string in my Vue app in the same way I would use title1... like a variable called title1nospaces.
I'm not sure if I should be using a computed property or a method. Anything I've tried always comes back as "title1nospaces" is not defined on the instance but is referenced during render".
Any help appreciated.

var str = " This is a test ";
var new_str = str.split(' ').join('');
console.log(new_str); // 'Thisisatest'

In your vue app, you should add a mixin and in that mixin you should implement a method that takes an input with spaces and it should return the output as a string without a spaces (or formatted string).
E.g.
let myApp = new Vue({
mixins: [CommonUtils],
});
CommonUtils.js code ( I am using ES6 syntax):
export default {
methods: {
myStringFormattingFun(input) {
// Do your magic and return the formatted string
}
}
}
OR you can just implement the function in your myApp component (main component).

Related

Can I observe the change fo a variable in Kotlin?

I know I can use get a notification when the value of a variable has changed, Code A is OK.
I hope to monitor the change of a normal variable such as var myFilename="OK" in Code B, but myObserv isn't launching when myFilename has changed.
Can I observe the change fo a variable in Kotlin?
Code A
var savedFilename: String by Delegates.observable("") {
prop, old, new -> ...
}
Code B
var myFilename="OK"
var myObserv String by Delegates.observable(myFilename) {
prop, old, new -> ...
}

In a Postman pre-request-script, how can I read the actual value of a header that uses a variable

I have a variable called token with a specific value myTokenValue
I try to make a call that includes that variable in a header, tokenHeader:{{token}}
I also have a pre-request-script that needs to change the request based on the value of the token header, but if I try to read the value pm.request.headers.get('tokenHeader') I get the literal value {{token}} instead of the interpolated myTokenValue
How do I get this value without having to look at the variable directly?
You can use the following function to replace any Postman variables in a string with their resolved values:
var resolveVariables = s => s.replace(/\{\{([^}]+)\}\}/g,
(match, capture) => pm.variables.get(capture));
In your example:
var token = resolveVariables(pm.request.headers.get('tokenHeader'));
Basically I was missing a function to interpolate a string, injecting variables from the environment
There are some workarounds:
write your own function, as in this comment by pomeh
function interpolate (value) {
return value.replace(/{{([^}]+)}}/g, function (match, $1) {
return pm.variables.get($1);
});
}
use Postman's own replaceSubstitutions, as in this comment by codenirvana
function interpolate (value) {
const {Property} = require('postman-collection');
let resolved = Property.replaceSubstitutions(value, pm.variables.toObject());
}
Either of these can be used as
const tokenHeader = interpolate(pm.request.headers.get('tokenHeader'));
but the second one is also null safe.

pass data to another route without messing with url

DISCLAIMER: I'm a noob.. sorry
Say I have 2 different components that are siblings:
comp1 and comp2
I wish to route from comp1 to comp2 with a bunch of data. How can I achieve this without getting a fugly url-bar containing everything?
I've tried using a separate class, lets call it DataTransmitter:
data-transmitter.js:
export class DataTransmitter {
constructor() {
this.val= "a";
}
}
comp1.js:
import { DataTransmitter } from './data-transmitter';
#inject(DataTransmitter)
export class comp1{
constructor(DataTransmitter){
this.DataTransmitter = DataTransmitter;
}
someMethod(){
this.DataTransmitter.val = "b";
console.log('comp1: ' + this.DataTransmitter.val);
}
}
comp2.js:
import { DataTransmitter } from './data-transmitter';
#inject(DataTransmitter)
export class comp2{
constructor(DataTransmitter){
this.DataTransmitter = DataTransmitter;
}
someMethod(){
console.log('comp2: ' + this.DataTransmitter.val);
}
}
This gives me the output:
comp1: b
comp2: a
I've also tried messing around with EventAggregator, but no success.
Is there some way of routing with parameters WITHOUT having a url that looks like site/comp2?data=stuff&things=otherstuff&params=values&more=etc?
You absolutely want to use a singleton class and then inject it inside of whatever components you need your data. The link that Gaby posted is definitely what you want to do.
The reason your posted code does not work is because you're attempting to use the inject decorator, but you're not importing it. Please see this working example of what you are trying to do on Gist.run here. I have two components, you can click to route between them and set the value. You'll notice the set value remains when you navigate back and forth.

Variables lose value swift

I have an app that stores a players name and score inside the variables
"CurrentPlayer" and "CurrentPlayerScore". this works just fine. but when I switch to another view, which displays the name and their score (which works fine.), and then I switch back both my variables lose their value. any help is appreciated and i'm pretty new to swift so the clearer the better. thanks. (also I have used the prepare for segue method, which works for passing information to my next view controller but not back)
You can use a global variables. There are defined in the global scope and can be accessed from everywhere in your project.
import UIKit
// globale Variablen
var global_address : String = ""
var global_username : String = ""
var global_password : String = ""
// globale Variablen
class ViewController
{
// ....
}

var within firebase set

I am trying to create some dynamic JSON based on a value of a name like below
this.merchantFirebase.child(firebase.auth().currentUser.uid).update({
this.props.data.name: {
status: this.state.productSwitch
}
});
I was thinking this would create something like
this.merchantFirebase.child(firebase.auth().currentUser.uid).update({
latte: {
status: this.state.productSwitch
}
});
but it is just given me an error of unexpected token
You'll need to use a different notation for this:
var updates = {};
updates[this.props.data.name] = { status: this.state.productSwitch };
this.merchantFirebase.child(firebase.auth().currentUser.uid).update(updates);
By using square-bracket notation, JavaScript "knows" that it needs to evaluate this.props.data.name as an expression, instead of using it as the literal name of the property (as it tries to do in your code).