I'm trying to track a custom event based on some data, for this I'm spying on my custom event and expecting the event to get trigger or not. Here am trying to reset my spyevent all I get is undefined error
TypeError: undefined is not an object (evaluating 'spyOnEvent(document, 'product.trackVariantChanged').calls.reset')
it('selects a variant without triggering the product.trackVariantChanged event on document', function() {
spyOnEvent(document, 'variantChanged');
spyOnEvent(document, 'product.trackVariantChanged').calls.reset();
App.ColorSelector.init(); // this function automatically calls custom triggers when it calls
App.ColorSelector.selectVariant($colorSelector, 'wms_III_black'); //this function has a depedency on init()
expect('variantChanged').toHaveBeenTriggeredOn(document);
expect('product.trackVariantChanged').not.toHaveBeenTriggeredOn(document);
App.ColorSelector.selectVariant($colorSelector, 'wms_III_white');
expect('variantChanged').toHaveBeenTriggeredOn(document);
expect('product.trackVariantChanged').not.toHaveBeenTriggeredOn(document);
});
from above case App.ColorSelector.init(); this function automatically calls/ should get call fisr and triggers custom event and App.ColorSelector.selectVariant($colorSelector, 'wms_III_black'); this function has a dependency on init() function
So I want to reset the spy before the selectVariant function get called.
For spyOnEvent instead of calls.reset() use spyOnEvent(document, 'customEvent').reset(); it will work.
Related
I am calling afterSave method in application.php to perform action on all models saving event. Issue is whenever I using SAVE method inside afterSave method application showing fatal error:
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
Point is same method working fine in specific model, without any memory exhausted error, I think there is something that need to be fixed over database connection. Below is the code which one I am trying.
//Application.php file
namespace App;
...
...
\Cake\Event\EventManager::instance()->on(
'Model.afterSave',
function (
\Cake\Event\EventInterface $event,
\Cake\Datasource\EntityInterface $entity,
\ArrayObject $options
) {
$auth_data = isset($_SESSION['Auth'])?$_SESSION['Auth']:[];
$ActionLogs = TableRegistry::get('ActionLogs');
$ActionLogsEntity = $ActionLogs->newEmptyEntity();
$ActionLogsEntity->change_log = $change_log;
$ActionLogsEntity->action_taken_by = $auth_data->username;
$ActionLogs->save($ActionLogsEntity); //This statement working fine in specific modelTable
class Application extends BaseApplication
implements AuthenticationServiceProviderInterface
{
...
...
}
Aside from the fact that the code should go into the Application class' bootstrap() method as mentioned in the comments, when you save inside of an afterSave event that listens to all models, then you naturally create a recursion, as saving the log will trigger an afterSave event too.
You have to put a safeguard in place that prevents the logging logic from running when the afterSave event belongs to the logging model, for example:
if ($event->getSubject() instanceof \App\Model\Table\ActionLogsTable) {
return;
}
// ...
I have a component where each row is a separate component. I'm emitting an event using Echo + Pusher, and I want to scope the event to only refresh the relevant row.
This isn't described in the docs, but there's an old (and possibly outdated) video by Caleb Porzio (creator of Livewire) in this article (last video, ~8m30s) where this is done by adding the relevant ID into the event name.
In my livewire model, I have:
public function getListeners()
{
return [
"HitReceived:{$this->monitorId}" => 'refresh',
];
}
And in my JS I have:
Livewire.emit('HitReceived:' + data.monitorId);
I can see in the console that data.monitorId is set. When I fire an event with id #1, I get a 500 error:
ERROR: Undefined array key "HitReceived1" {"userId":1,"exception":"[object] (ErrorException(code: 0):
Undefined array key \"HitReceived1\" at /vendor/livewire/livewire/src/ComponentConcerns/ReceivesEvents.php:72)
(This all works if I don't scope my event to a particular model instance, but then everything refreshes.)
I was using $this->monitorId in my array of listeners:
public function getListeners()
{
return [
"HitReceived:{$this->monitorId}" => 'refresh',
];
}
But the variable was declared as protected:
protected $monitorId;
I can't quite see why this would have cause the error I was seeing, but changing it to a public property resolved the issue.
When calling Xrm.Page.data.refresh(true) from a web resource, I get this error:
Unable to get property 'refreshRibbon' of undefined or null reference
in the JSProvider.ashx refreshRibbon, from firing an onchange event for an Attribute.
Why is this error occurring?
This is an interesting bug/feature with the onChange event:
function onLoad() {
Xrm.Page.getAttribute("new_att").addOnChange(onChange); // OK!
Xrm.Page.getAttribute("new_att2").addOnChange(Xrm.Page.ui.refreshRibbon); // No Worky!
}
Any calls to Xrm, should be wrapped in another function, or an anonymous method. No passing in the function directly.
function onChange() {
Xrm.Page.ui.refreshRibbon();
}
I have an observer module that I have written for Magento. It simply monitors an event called mgd_order_prep which is triggered by a custom dispatcher like this:
Mage::dispatchEvent("mgd_order_prep", array('orderdata' => $order));
$order is simply a magento sales/order object.
My event fires and my function in the proper class executes:
function updateOrderPrepPDF($observer)
{
Mage::log("Update Order Prep",null,'orderprep.log');
Mage::log($observer->getOrderdata(),null,'orderprep.log');
}
I see what I should after the first log event, but I dont see ANYTHING for when I try to output the order data (it outputs blank - or null).
How do I get the data I pass in at the dispatch event out at the execution point?
You can directly get Data using getData() method :
function updateOrderPrepPDF($observer)
{
Mage::log(print_r($observer->getData(),true),null,'orderprep.log');
}
Check this log inside var/log directory.
Try this code and let me know if you still have any query.
I have a custom event that I want to fire using jQuery's trigger method:
$(wizard).trigger('validatingStepValues');
Then in the wizard's current step code, I subscribe to this event as follow:
$(wizard).bind('validatingStepValues', function (){
// Validating step's form data here; returning false on invalid state.
});
Then in my wizard, again I want to be able to stop user from going to the next step, if a false value is returned from validation process? I'd like to have something like:
$(wizard).trigger('validatingStepValues', validReturnCallback, invalidReturnCallback)
Have you considered using something like:
function wizardValidator(successCallback, failureCallback) {
return function() {
// Validating step's form data here;
if (wasValid && successCallback) {
successCallback();
}
else if (! wasValid && failureCallback) {
failureCallback();
}
return wasValid;
};
}
$(wizard).bind('validatingStepValues', wizardValidator(validReturnCallback, invalidReturnCallback));
This requires that you know the callbacks that you want to use at the time you bind the event listener. If you want to be able to use different callback functions at different times, you could define additional event types, like:
$(wizard).bind('validatingStep2Values', wizardValidator(validStep2ReturnCallback, invalidStep2ReturnCallback));
$(wizard).bind('validatingStep3Values', wizardValidator(validStep3ReturnCallback, invalidStep3ReturnCallback));
Alternately, events that you create by calling trigger() propagate up the DOM hierarchy. Returning false an event handler cancels this propagation. So you could bind your desired success callback function as an event listener on your wizard's parent node. That won't do anything to allow your failure callback to be executed, however.