Loading resources on OnLoad function

I am trying to load a json file using the cc.loader.load function in onLoad() function as shown below, I also have used some console.log() functions to see the order of execution.

const {ccclass, property} = cc._decorator;  @ccclass export default class NewClass extends cc.Component {  // LIFE-CYCLE CALLBACKS:  objectFromResource: Object  onLoad () {     console.log("Starting onLoad() Function")     var url = cc.url.raw('resources/json_resource.json')     cc.loader.load(url, (err, res) => {         cc.log(res)         this.objectFromResource = res         console.log("Loaded URL")     });     console.log("Ending onLoad() Function") }  start () {     console.log('Starting start() Function')     console.log(this.objectFromResource) //logging as null     console.log('Ending start() function') }  update (dt) {  }  } 

The output is as following:

Cocos Creator v2.1.1 JSONReader.ts:16 Starting onLoad() Function JSONReader.ts:33 Ending onLoad() Function JSONReader.ts:37 Starting start() Function JSONReader.ts:38 undefined JSONReader.ts:39 Ending start() function JSONReader.ts:22 {__type__: "cc.JsonAsset", _name: "json_resource", _objFlags: 0, _native: "", json: Array(784)} JSONReader.ts:24 Loaded URL 

The resource is loaded after the onLoad() and start() functions are completed. How to load the resource on OnLoad() function before the start() method is called?

Spotify API: this.state.data.map is not a function

Eu estou tentando passar os dados da api para uma componente filho, porem sempre ta dando esse erro quando eu digitando o nome do cantor no input, pois desejo fazer o fetch a cada letra digitada, não apenas apos completar o nome.

Os dados estão chegando normalmente, pelo console.log pude ver que estão todos lá, então acredito que seja realmente um problema no .map

import React, { Component } from 'react'; import ItemPage from './apiUnica';  import querystring from 'querystring';   class api extends Component { constructor(props){     super(props);     this.state = {data: [], isLoaded: false, display_name: '' } }  componentDidMount(){     const accessToken = window.location.search.slice(14);     fetch('https://api.spotify.com/v1/me', {headers: {'Authorization': 'Bearer '+accessToken}})         .then(response => response.json())         .then(data => this.setState({display_name: data.display_name, isLoaded: true})) }  async updateResult(){     const artist = document.getElementById("singer").value;     const accessToken = window.location.search.slice(14);     await fetch('https://api.spotify.com/v1/search?'+querystring.stringify(         {q: artist,         type: 'artist',         limit: '5'     }),      {headers: {'Authorization': 'Bearer ' + accessToken}})             .then(response => response.json())             .then(data => this.setState({                  data: data.artists             }))          if(this.state.data){     console.log(this.state.data)     } }  render(){     return(         <div>                    <div>                 <input type="text" onChange={this.updateResult.bind(this)} id="singer"/>                 {!this.state.isLoaded ? <h1>Carregando</h1> : <h1>Bem vindo {this.state.display_name}</h1>}                 {!this.state.data ? 'missing data'  : this.state.data.map(item => <ItemPage singerName={item.artists.name} />)}             </div>         </div>     ); } 

Magento CE 2.3.2 TypeError: setCouponCodeAction.registerDataModifier is not a function

After updating Magento CE 2.3.1 to 2.3.2 incl. updating libsodium we have trouble with our checkout.

When trying to access the checkout – does not matter which way – we get the following TypeError:

TypeError: setCouponCodeAction.registerDataModifier is not a function. 

In our theme we moved the voucher section to the right sidebar but that wasn’t a problem in Magento CE v2.3.1.

Any idea what to do?

Plain Text validation on presave function sharepoint

I have OOTB list. On new item adding I want to validate, on drop-down selection if value is USA three multi-line text box will show with mandatory field. I know we have to write validation on PreSave function but I like to have validation like SharePoint OOTB not alert.

Below is my code:

$  (document).ready(function(){     $  ('nobr:contains("Email Subject")').closest('tr').hide();      $  ('nobr:contains("Email Body")').closest('tr').hide();     $  ('nobr:contains("End SLA")').closest('tr').hide();      //Show/hide columns based on Drop Down Selection      $  ("select[title='Country']").change(function() {         if ($  ("select[title='Country']").val() == "USA")          {             $  ('nobr:contains("Email Subject")').closest('tr').show();              $  ('nobr:contains("Email Body")').closest('tr').show();             $  ('nobr:contains("End SLA")').closest('tr').show();          }          else          {             $  ('nobr:contains("Email Subject")').closest('tr').hide();              $  ('nobr:contains("Email Body")').closest('tr').hide();             $  ('nobr:contains("End SLA")').closest('tr').hide();          }     }); }); 

How to plot the result of Grad function?

When I calculate the gradient of a two dimension function like $ r=\frac{1}{\sqrt{x^2+y^2}}$ with the syntax of

h[x_,y_]:=Grad[1/r,{x,y}] 

and when I checked the result with

h[x,y][[1]] h[x,y][[2]] 

I got a right result of $ -\frac{x}{(\sqrt{x^2+y^2})^{-3/2}}$ and $ -\frac{y}{(\sqrt{x^2+y^2})^{-3/2}}$ , respectively.

However, when I tried to plot the function with syntax of

VectorPlot[{h[x,y][[1]],h[x,y][[2]]},{x,0.1,0.3},{y,-0.3,0.3}] 

I found the value in y direction is 0, and I also confirmed with

Plot3D[h[x,y][[1]],{x,-0.3,0.3},{y,-0.3,0.3}] Plot3D[h[x,y][[2]],{x,-0.3,0.3},{y,-0.3,0.3}] 

and the results are that the first one has a proper plot while the second one shows the function value is 0.

Would anyone give me some clue that how this happened? Thank you and best regards!

Time complexity, Big-O for this function?

def f(n):     if n < 100000:         return 0;     for(int i = 0; i < n*n; i++){         return f(n-1) 

What is the time complexity?


My answer is $ O((n!)^2)$ . Here’s my thought process:

  1. The for loop will be running $ n^2$ the first time.

  2. However, during the first loop (i.e., $ i = 0$ ), it will call $ f(n-1)$ , hence the next for loop will be $ (n-1)^2$ .

  3. This will keep going until $ n <10000$ (base case). Assuming $ n$ is very huge, the number of calls for each function to base case is essentially $ n$ times.

  4. Now, considering all the for loops, the total number of calls is essentially $ n^2 \cdot (n-1)^2 \cdot (n-2)^2 \cdots 1!$ (there will be a total of $ n$ times multiplication, and each multiplication will be $ n-1$ of the previous one because of $ f(n-1)$ call).

Does JavaScript stop executing script when a Web Assembly function is called?

I am fairly inexperienced with web development and want to put a lot of time into learning JavaScript and Web Assembly because they both seem like extremely powerful tools when used together. When structuring my projects should I assume that the V8 engine will just stop executing code when I run a wasm function from JS, or will they run simultaneously?