Altertative solution to require dinamically in React-Native - react-native

I have a vector of strings and I want to use each element of that vector with require like that
for(var i = 0; i< happy_songs.melodies.length;++i)
{
var track = '../resources/'
track += happy_songs.melodies[i]
console.log(track)
var song = require(`../resources/${happy_songs.melodies[i]}`)
}
I have tried several syntax approaches but none of them worked, always having a syntax error at the require.
Is there any alternative solution to require which can do the job I want ?
PS: I don't know if this matters but those lines of code are used in an async function.

Hi you can use a aux var as:
var songSource= [path1,path2,...] and use the index as interator to use dinamically

Related

In Umbraco, how to handle tag datatypes with Examine?

I have made a search page using Examine which for the moment works fine and as intended (still needs to get paging sorted...), but I have run into an issue. I also want the page to function as a related tags page, as in an article can have several tags, and if you click a tag you can see related articles with the same tag. Pretty basic stuff. Only I have found out that Examine cant really handle tag data types because as I understand they are stored in a comma delimited list, something Examine cant handle in this case. I have searched around and found only a few hints of others having the same problem, one with an actual solution but that sadly no longer works in Umbraco 10: Umbraco - Using Examine to search Umbraco.Tags
Also found this more recent one, but kind of a dead end: https://our.umbraco.com/forum/umbraco-8/98761-how-to-match-tags-in-examine-in-v8-theyre-now-stored-as-a-json-string-array
So yeah, what the heck do I do?
For good measure here is my examine code:
#{
Layout = "master.cshtml";
var searchQuery = !string.IsNullOrWhiteSpace(Context.Request.Query["q"].ToString()) ? Context.Request.Query["q"].ToString() : "";
var tags = !string.IsNullOrWhiteSpace(Context.Request.Query["tags"].ToString()) ? Context.Request.Query["tags"].ToString() : "";
var parent = !string.IsNullOrWhiteSpace(Context.Request.Query["parent"].ToString()) ? Convert.ToInt32(Context.Request.Query["parent"].ToString()) : 1088;
if (!examineManager.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out IIndex index))
{
throw new InvalidOperationException($"No index found by name{Constants.UmbracoIndexes.ExternalIndexName}");
}
var searcher = index.Searcher;
var criteria = searcher.CreateQuery(IndexTypes.Content);
var filter = criteria.ParentId(parent).AndNot(x => x.Field("umbracoNaviHide", 1.ToString()));
if (!string.IsNullOrWhiteSpace(tags))
{
filter.And().Field("tags", tags);
}
if (!string.IsNullOrWhiteSpace(searchQuery))
{
filter.And().ManagedQuery(searchQuery);
}
var res = filter.Execute();
}

Semantic Tokens in MarkupString / MarkupContent

Is it possible to use MarkdownString/MarkupContent with code or pre with span to emulate semantic tokens in Hover? If so, is it possible to access the colors from the user's theme using only the CSS on the span elements? Ideally I would like to avoid using anything VSCode specific.
I saw https://github.com/microsoft/vscode/issues/97409 but there was no solution.
If you want to manually set colors for code you can try this:
// using your fileSelector
let disposable = vscode.languages.registerHoverProvider('plaintext', {
provideHover(document, position) {
const codeBlock = `<code><span style="color:#f00;background-color:#fff;">const</span> a = 12</code>`;
const markdown = new vscode.MarkdownString();
// markdown.appendCodeblock(codeBlock, "javascript");
markdown.appendMarkdown(codeBlock);
markdown.supportHtml = true;
markdown.isTrusted = true;
return new vscode.Hover(markdown, new vscode.Range(position, position));
}
});
<pre> also works, instead of <code>, but I think <code> looks better.

Convert Feature Layer to an array of Polygons in ArcGIS JS?

Pretty straight forward: I am simply trying to get a feature layer
var floodLayer = new FeatureLayer("URL");
and convert it to a polygon array similar to:
var polygons = [];
for (var i = 0; i < floodLayer.graphics.length; i++) {
var polygons[i] = new Polygon({ "rings": floodLayer.graphics[i].rings, "spatialReference": floodLayer.graphics[i].spatialReference });
}
However, feature layers don't appear to have the appropriate properties to create polygons. Unless I am missing something?
rings and spatialReference are properties of geometry which is a property of your graphics. So you need to use floodLayer.graphics[i].geometry.rings instead of floodLayer.graphics[i].rings, for example.

Find a value in json object using lodash methods flatten and find

Using lodash i want to find a team whose id is 3229. I tried following but it is not returning anything.
var team = _.chain(data.teams)
.flatten("divisionTeams")
.find({"id":3229})
.value();
Here is my plunker code.
http://plnkr.co/edit/UDwzRkX3zkYjyf8UwO7I
For the Json data please see the file data.js in Plunker.
Please note i cannot change the json data since i am calling a test api.
flatten doesn't take that argument, see docs. You need to either map or pluck the divisionTeams.
_.chain(data.teams)
.pluck('divisionTeams')
.flatten()
.find({id: 3232})
.value();
So if the requirements are to only use flatten, find, and lodash, that's going to be difficult. But using a for loop to get the division teams might be what you're asking.
var teams = [];
for(var e of data.teams) {
teams.push(e.divisionTeams);
}
var blah = _.flatten(teams, true);
console.log(_.find(blah, function(item) { return item.id == 3222; }));

How can I remove all items from a Dojo dstore?

I am having trouble removing all items from a dstore. I am trying this, which seems like it should work, but it fails at the end:
var TrackableMemory = declare([ Memory, Trackable ]);
var userMem = new TrackableMemory({
data: {the data...},
idProperty: '_id'
});
userMem.forEach(function (userObj) {
userMem.remove(userObj._id);
});
I put up a working (or not working, rather) example in this fiddle. See the console for the "cannot read property '_id' of undefined" error when it can't find the last record.
I have other things connecting to this store instance, so I can't really just reset everything by redefining userMem.
What am I doing wrong? How can I remove all items from a dstore?
Turned out to be a simple JS array problem of modifying the array over which I was iterating. Looping backwards over the array with a simple for works:
userMem.fetch().then(function (users){
for (var i = users.length - 1; i >= 0; i--) {
userMem.remove(users[i]._id);
}
});
This worked for me
// Forget all data
myGrid.store.data = [];
// Refresh the grid
myGrid.refresh();