I am new to cypress and I'm trying to perform drag and drop.
I need to set the position on the drag element
cy.get(dragElementCss).drag(dropElementCss, { source: { x: 100, y: 100 }, target: { position: 'left' }, force: true });
And I get the follwoing error :
No overload matches this call.
Overload 1 of 3, '(targetSelector: keyof HTMLElementTagNameMap, options?: Partial<ClickOptions & { source: ClickOptions; target: ClickOptions; }>): true', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'keyof HTMLElementTagNameMap'
Can anybody please tell what is wrong with the above code?
Related
I have a common dispatcher to update multiple states as shown below:
updateConfiguration: (state, action) => {
const { type, payload } = action.payload
const { dispatchKey, stateKey } = keyHelpers[type as keyof keyHelpersType]
state[stateKey] = payload[dispatchKey]
}
where keyHelpers is as shown below:
export const keyHelpers: keyHelpersType = {
[actionTypes.addUser]: {
dispatchKey: 'user',
stateKey: 'user',
}
When writing the dispatch logic in my reducer I am getting the following error in following line:
state[stateKey] = payload[dispatchKey]
Error:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'WritableDraft<configSlice>'
I tried doing:
state[stateKey as keyof typeof state] = payload[dispatchKey]
but this didn't work as well throwing:
Type 'any' is not assignable to type 'never'.ts(2322)
Can someone help me resolve this?
You probably have to add an as const assertion:
export const keyHelpers: keyHelpersType = {
[actionTypes.addUser]: {
dispatchKey: 'user',
stateKey: 'user',
}
} as const
That way it will not be string, but "user".
In Tone.js I have made a class that creates a synth instance where .play() is called in a sequencer function, thereby playing a sound. In the class below there are absolutely no problems when this.synth in updateSynthType is a monophonic Tone.Synth, but the whole thing breaks when it is Tone.Polysynth and I receive the following error when trying to call updateSynthType.
Uncaught Error: Synth was already disposed
at ti (Tone.js:1)
at ra._scheduleEvent (Tone.js:21)
at Object.callback (Tone.js:21)
at Gi._timeoutLoop (Tone.js:21)
at Gi.emit (Tone.js:7)
I don't understand why this never happens with a regular Tone.Synth but when I try to change a Tone.PolySynth an error appears. I am trying to update the settings to change between the type of polysynth (e.g. Synth, AMSynth, MetalSyth etc). How can I stop this problem? Why does this class only work for a regular Tone.Synth? Is there a better way of updating the PolySynth type in this class?
Here is the class in question:
class PolyInstrument {
constructor(){
this.synth = null
this.gain = new Tone.Gain()
this.gain.toDestination()
}
play(note = null, beat, time = null){
if (this.synth){
if (note === null){
time ? this.synth.triggerAttackRelease(beat, time) : this.synth.triggerAttackRelease(beat)
} else {
time ? this.synth.triggerAttackRelease(note, beat, time) : this.synth.triggerAttackRelease(note, beat)
}
} else {
alert('error: no synth')
}
}
get defaultSettings(){
return {
Synth: {
oscillator: {
type: 'triangle'
},
envelope: {
attack: 0.005,
decay: 0.1,
sustain: 0.3,
release: 1
}
},
AMSynth: {
harmonicity: 3 ,
detune: 0 ,
oscillator: {
type: 'sine'
},
envelope: {
attack: 0.01 ,
decay: 0.01 ,
sustain: 1 ,
release: 0.5
},
modulation: {
type: 'square'
},
modulationEnvelope: {
attack: 0.5 ,
decay: 0 ,
sustain: 1 ,
release: 0.5
}
}
}
}
updateSynthType(synthType){
if (this.synth){
this.synth.disconnect(this.gain)
this.synth.dispose()
}
let settings = this.defaultSettings[synthType] || {}
this.synth = new Tone.PolySynth(Tone[synthType], settings)
this.synth.connect(this.gain)
this.play()
}
}
Thanks for reading.
Instead of using synth.dispose(), call synth.releaseAll().
https://tonejs.github.io/docs/14.7.77/PolySynth#releaseAll says:
Trigger the release portion of all the currently active voices immediately. Useful for silencing the synth.
I was able to fix this by clearing out the context timeline before disposing:
synth.context._timeouts.cancel(0);
synth.dispose();
For writing yet another lint in Rust, I need to make sure that the type of an Expr is actually an Option<_> (or any pointer to one). I have already walked any ptrs and rptrs to their conclusion and am left with a rustc::middle::ty that in my test case debugs to (manually formatted for better readability):
TyS {
sty: ty_enum(
DefId {
krate: 2,
node: 117199
},
Substs {
types: VecPerParamSpace {
TypeSpace: [
TyS {
sty: ty_int(i32),
flags: 0,
region_depth: 0
}
],
SelfSpace: [],
FnSpace: [],
},
regions: NonerasedRegions(
VecPerParamSpace {
TypeSpace: [],
SelfSpace: [],
FnSpace: [],
}
)
}
),
flags: 0,
region_depth: 0
}
However, now I'm a bit lost – how do I find out if the TyS is actually an Option<_> type?
You need use with_path on the DefId. You will be provided an iterator over PathElems which you must consume.
The following is a rough sketch, but should give you an array of Names if you tweak it a bit.
if let ty_enum(did, ..) = ty.sty {
tcx.with_path(did, |iter| iter.map(|elem| elem.name())).collect::<Vec<Name>>;
}
Is there any way to implement nsICommandLineHandler in a restartless add-on?
It seems possible from https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/platform/xpcom.html , but this code (run from within exports.main) is not working for me:
var { Class } = require('sdk/core/heritage');
var { Unknown, Factory } = require('sdk/platform/xpcom');
var { Cc, Ci } = require('chrome');
var contractId = '#mozilla.org/commandlinehandler/general-startup;1?type=webappfind';
// Define a component
var CommandLineHandler = Class({
extends: Unknown,
get wrappedJSObject() this,
classDescription: "webAppFinder",
/* Not used by SDK, so commenting out
_xpcom_categories: [{
category: "command-line-handler",
// category names are sorted alphabetically. Typical command-line handlers use a
// category that begins with the letter "m".
entry: "m-webappfind"
}],
*/
helpInfo : " -webappfind Open My Application\n",
// nsICommandLineHandler
handle : function clh_handle(cmdLine) {
try {
console.log('good so far'); // Doesn't actually reach here
var fileStr = cmdLine.handleFlagWithParam("webappfind", false);
if (fileStr) {
console.log('made it');
}
}
catch (e) {
Cu.reportError("incorrect parameter passed to -webappfind on the command line.");
}
if (cmdLine.handleFlag("webappfind", false)) { // no argument
cmdLine.preventDefault = true;
throw 'A valid ID must be provided to webappfind';
}
},
hello: function() {return 'Hello World';}
});
// Create and register the factory
var factory = Factory({
contract: contractId,
// id: '{7f397cba-7a9a-4a05-9ca7-a5b8d7438c6c}', // Despite the docs saying one can add both, this doesn't work
Component: CommandLineHandler
});
I have the following code afterward which works...
// XPCOM clients can retrieve and use this new
// component in the normal way
var wrapper = Cc[contractId].createInstance(Ci.nsISupports);
var helloWorld = wrapper.wrappedJSObject;
console.log(helloWorld.hello());
...but Firefox is not accepting command line args as per this error:
Error: Warning: unrecognized command line flag -webappfind
Source file: resource://app/components/nsBrowserContentHandler.js
Line: 765
UPDATE
I've now taken #nmaier's advice to add categories and therefore added these lines afterward:
var catMan = Cc['#mozilla.org/categorymanager;1'].getService(Ci.nsICategoryManager); //
catMan.addCategoryEntry('command-line-handler', 'm-webappfind' /*contractId*/, contractId, false, true);
But I'm getting these 3 errors when invoking from the command line:
Error: [Exception... "'Failure' when calling method:
[nsIFactory::createInstance]" nsresult: "0x80004005
(NS_ERROR_FAILURE)" location: "native frame :: ::
:: line 0" data: no]
Contract ID
'#mozilla.org/commandlinehandler/general-startup;1?type=webappfind'
was registered as a command line handler for entry 'm-webappfind', but
could not be created.
Error: Warning: unrecognized command line flag -webappfind
Source file: resource://app/components/nsBrowserContentHandler.js
Line: 765
The SDK will not register categories for you.
Some remarks regarding categories can be found here:
https://stackoverflow.com/a/18366485/484441
But still, I'm not sure if bootstrapped extensions are actually started before the initial command line is processed. Trial and error, I guess...
Edit:
Your component does not specify any interfaces, hence it does only support nsISupports.
The SDK module docs state that you should add an interfaces: [ 'nsICommandLineHandler' ] property.
I have a Meteor Handlebars template helper that is representative of most of my template helpers as shown below.
# Address Form Controls Template
Template.AddressFormControls.helpers
address1: () ->
if typeof Session.get('edit-building') is 'string'
building = Buildings.findOne(Session.get('edit-building'))
return building?.address?.address1
address2: () ->
if typeof Session.get('edit-building') is 'string'
building = Buildings.findOne(Session.get('edit-building'))
return building.address.address2
city: () ->
if typeof Session.get('edit-building') is 'string'
building = Buildings.findOne(Session.get('edit-building'))
return building.address.city
state: () ->
if typeof Session.get('edit-building') is 'string'
building = Buildings.findOne(Session.get('edit-building'))
return building.address.state
zip_code: () ->
if typeof Session.get('edit-building') is 'string'
building = Buildings.findOne(Session.get('edit-building'))
return building.address.zip_code
main: () ->
if typeof Session.get('edit-building') is 'string'
building = Buildings.findOne(Session.get('edit-building'))
return building?.phone?.main
fax: () ->
if typeof Session.get('edit-building') is 'string'
building = Buildings.findOne(Session.get('edit-building'))
return building?.phone?.fax
You will notice that every helper contains an if statement to see if the Session variable is a string. If it's a string, then it should be an ID that can be used to perform the search for the needed object.
It seems like such a waste to have that repeated throughout a project for the various collections that one uses.
How can I DRY this up?
Help me Obiwan you're my only hope!
You could shorten it with something like
js:
main:function() {
building = Buildings.findOne({_id:Session.get('edit-building')})
return building && building.phone && building.phone.main;
}
coffee:
main: () ->
building = Buildings.findOne(_id: Session.get("edit-building"))
building and building.phone and building.phone.main
The key difference being explicitly saying you want the _id to match. So in the case the Session variable for edit-building doesn't exist, isn't a string or doesn't match any records nothing is returned.
Just this might shorten your code a lot too:
building: () ->
Buildings.findOne(_id: Session.get("edit-building"))
Then in your html (in the AddressFormControls template) you could do:
{{#if building}}
Phone: {{building.phone.main}}
Fax: {{building.phone.fax}}
....
{{/if}}