I'm doing a Coursera course from Meta and I'm getting an error importing an api file.
We need to import this raw file from GitHub that contains three functions: seededRandom, fetchAPI, submitAPI.
Next, we need to use fetchAPI that receives a date as parameter and submitAPI that returns a boolean value. The problem is when i'm trying to use these functions React throws an error because functions are not defined.
I tried to use them from "window" global variable, but it still doesn't work.
Thanks you for your help!
I tried to use them from "window" global variable, but it still doesn't work.
Related
I'm creating a project in ReactJS. I have a context folder that contain different context folders. It looks like this.
Each of the folder has ...Context.js, ...Reducer.js, and ...State.js files. In my AuthStaste.js, I have a clearError() function as shown here:
In my ContactState.js, I have error object property declared in the initialState. Since I already have clearError defined in AuthState.js, I want to know if there is a way I can make use of the function in my ContactState.js without redefining it.
Just trying and testing CKAN going through the documentation. So far so good but I'm having trouble initializing a JavaScript module.
I followed these steps, http://docs.ckan.org/en/latest/theming/javascript.html#initializing-a-javascript-module, restarted the server, loaded the page and the button is there, I can see the newly created JS file in the page but it's not being initialized so no output in the console.
If I add another console.log anywhere not inside initialize: function () {} in the JS file it gets outputted.
Maybe some other steps missing here? Do I need to register the CKAN module somewhere?
I am trying to write specs for a JavaScript file (say 'functionality.js'). jQuery is the only external library used. I am using Karma as my test runner.
functionality.js in-turn refers to an object (say 'FOO') which is defined in a different file on which several methods are defined. The object FOO (and its methods) is used in several other files. I don't want to add in foo.js (where FOO is defined) to the list of files in Karma because that in turn makes use an object defined elsewhere and so on. I would like to be able to test functionality.js and others in isolation by mocking FOO as an empty object and be able to commonly use it in all my spec files. Would I be able to do that? Are there any other alternate patterns to this?
My trials: I tried creating a helper file and defined an empty FOO object wrapped in an IIFE, then added that file to Karma before I loaded my source JavaScript files, but it throws a ReferenceError saying can't find variable FOO in functionality.js:1
I use doT.js 1.0 for templating with requirejs.
My goal is to load a file called "length.html" from another file called "freight.html".
The advanced sample states that you can load files with
{{#def.loadfile('/snippet.txt')}}
So I tried using {{#def.loadfile('/length.html')}} in freight.html.
freight.html is in the same directory as length.html.
However, the javascript console throws an error:
Uncaught TypeError: Object #<Object> has no method 'loadfile'
How can I get loadfile to work? Or is the documentation wrong and there is no loadfile function?
It appears as though loadfile needs to be created by you, as per your requirements. If you are using express, I would suggest looking at https://github.com/nerdo/dot-emc. This module wraps doT so that you can use res.render() to return your templates. It also provides a nifty include function to solve the problem you have above. So instead of loadfile you would use:
{{#def.include('length')}}
Just be aware that if you use this module, the default file extension is .def, which needs to be changed with options to use say .html
I'm trying to develop a custom xtype that extends the tags xtype defined in
/libs/cq/tagging/widgets/source/widgets/TagInputField.js
I have the function defined in another file
CQ.tagging.customTagInputField = CQ.Ext.extend(CQ.TagInputField, { /*A whole bunch of code here */ });
CQ.Ext.reg("customtags", CQ.tagging.customTagInputField);
Yet every time I try to boot up a page containing my custom widget I get an error in my console saying
TypeError: sp is undefined
spp = sp.prototype;
According to the all wise and knowing Google. This kind of error usually means I'm trying to extend something that doesn't exist. However changing
CQ.Ext.extend(CQ.TagInputField,
to something a bit more specific like
CQ.Ext.extend(CQ.tagging.TagInputField,
Produces and error saying CQ.tagging is undefined. Is there a way for me to extend this file in CQ5? If so what am I doing wrong?
Within /libs/cq/tagging/widgets/source/widgets/TagInputField.js, you'll see that the tags widget is declared as CQ.tagging.TagInputField, so I believe your second approach of extending that field is correct.
You mentioned that your custom xtype is in a separate file - when your page loads and your extension code is invoked, has the tagging widgets library loaded? You may need to add the tagging category to your custom client lib as a dependency.
On custom JS clientlibs and dependencies:
http://helpx.adobe.com/cq/kb/HowToCreateCustomClientLib.html