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).
Related
I am trying to implement embedded language support for SQL in vscode extension using request forwarding mechanism.
According to the documentation we can hijack the completion using middleware option and provide the sub-language completion using an existing language server. As an example user can get CSS language support inside HTML using this mechanism.
In my scenario, I want get SQL Language support inside another language (new language) when writing a SQL query.
Sample Code
let clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: '.mylang' }],
middleware: {
provideCompletionItem: async (document, position, context, token, next) => {
if (
!isInsideSQLRegion(
myLanguageService,
document.getText(),
document.offsetAt(position)
)
) {
return await next(document, position, context, token);
}
const originalUri = document.uri.toString();
virtualDocumentContents.set(
originalUri,
getSQLVirtualContent(myLanguageService, document.getText())
);
const vdocUriString = `embedded-content://sql/${encodeURIComponent(originalUri)}.sql`;
const vdocUri = Uri.parse(vdocUriString);
return await commands.executeCommand<CompletionList>(
'vscode.executeCompletionItemProvider',
vdocUri,
position,
context.triggerCharacter
);
}
}
};
Here the provideCompletionItem get triggered each time we write a new character in the editor but it seems that it is not getting triggered when user writes " or single quote.
Is there a way to get provideCompletionItem when single or double quotes is being entered ?
I have a Vue.js app running with a GraphQL backend, and Gridsome as the Vue.js boilerplate generator.
I'm trying to write a GraphQL query to only return the data of the logged in user, like this :
query Blah($test: String!) {
db {
settings (where: {user_id: {_eq: $test}})
{
key
value
}
}
with the $test variable defined here:
export default {
data() {
return {
test: "Va123",
user: null
};
}
}
But I get this error message:
An error occurred while executing query for src/pages/Profile.vue
Error: Variable "$test" of required type "String!" was not provided.
This is for a Girdsome page, not a template
It looks like the only way is to create pages programmatically using createPage() and pass the page context variable down the the page-query.
https://gridsome.org/docs/pages-api/#the-page-context
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.
I have implemented HTTP adapter in IBM Worklight. I want to display the result returned from server. I want to display HTML file. My code is
function getFeeds() {
var input = {
method : 'get',
returnedContentType : 'text',
path : "marketing/partners.html"
};
WL.Logger.debug("sdfsds");
return WL.Server.invokeHttp(input);
}
I want to receive(display) WL.Server.invokeHttp(input). After receiving it I want to parse the data.
Take a look at the Server-side Development Getting Started Modules. Inside the HTTP adapter – Communicating with HTTP back-end systems Module on Slide 15 - 'XSL Transformation Filtering' will show you how to filter data you get back from the backend. Further parsing and showing data has to be done on the client using onSuccess callback for WL.Client.invokeProcedure. There's a module for that too.
Here's an example of getting data and showing to a user:
var invocationData = {
adapter : 'adapter-name',
procedure : 'procedure-name',
parameters : []
};
var options = {};
options.onSuccess = function (response) {
//response is a JavaScript object
$("#id").html(response.invocationResponse.text);
}
options.onFailure = function (response) {
alert('Failed!'); //You probably want something more meaningful here.
}
WL.Client invokeProcedure(invocationData, options);
There are JavaScript libraries you can add to make searching for values inside the JSON response easier, such as: jspath and jquery-jspath. There's also XPath if you're working with XML.
If you retrieve it as plain text, once you got it back to your application, do something like
$("#container-id").html(response.invocationResponse.text);
This will inject the HTML you've retrieved to an element with id container-id.
Is there a way to rename the query string parameter that holds the name of callback function? Say, I've got a legacy app which sources I can't access, I want it to be switched to ServiceStack, but the app uses "function" query string parameter, while SS expects "callback".
You can do it with a response filter, inside AppHost.Configure():
ResponseFilters.Add((req, res, dto) =>
{
var func = req.QueryString.Get("function");
if (!func.isNullOrEmpty())
{
res.AddHeader("Content-Type", ContentType.Html);
res.Write("<script type='text/javascript'>{0}({1});</script>"
.FormatWith(func, dto.ToJson()));
res.Close();
}
});