I'm in the process of upgrading to rev 1.0.0 build9. (Code was passing all tests with rev 0.7.3.)
In the template I have an element:
<div on-click='complaint_{{id}}_edit_cancel()'/>
The mustache interpolation within that attribute is causing a parser error. I realize that there may be other ways to pass this variable to the event handler, but how should such interpolation be handled so as not to trigger a parser error?
Not sure if this was officially supported or if this was a side-effect of attribute parsing (which would make it a bug). As far as I know, Ractive only supports either a string or a JS expression as values of the on-* directive. Also, a function per id is a strange setup.
Anyways, expressions have full, unmustached access to data in the context. You can pass i as an argument of either a method call or a proxy event.
// passes id as argument to a method
<div on-click="complaint_edit_cancel(id)"/>
// passes id as argument to an event, handled by ractive.on
<div on-click="['complaint_edit_cancel', id]"/>
Related
I'm new in redux toolkit and I've managed state with redux toolkit lately. But the thing I don't know, what is usage of first argument of CreateAsyncThunk. I've read this article: https://redux-toolkit.js.org/api/createAsyncThunk and according to this, CreateAsyncThunk has two argument and first argument is named type :
A string that will be used to generate additional Redux action type constants, representing the lifecycle of an async request
Ok. But we never need to call or use this argument again, so why is important to name this argument? I tried adsfds insted of requestStatus after / and my project worked perfectly! I also understand it also works even without slash.
It seems it doesn't matter what you write as first argument, It always works! So what is the usage of the first argument?
In Redux, every action is identified by a unique type string. So createAsyncThunk creates three actions for you - in your case with the type strings "adsfds/pending", "adsfds/fulfilled" and "adsfds/rejected".
If you do not use "asdfds" in any other createAsyncThunk, that's a perfectly fine thing to do, but if you look at the Redux Devtools browser extension to see what is happening in your application, a string like that might make it very difficult to read.
I have project, with some custom ConstraintValidator. I wanted to build custom message. I did so and everyting works just fine. Then we met need to have 'api' module, which means, that you have to split bean validation annotation and ConstraintValidator, have to use #Constraint(validatedBy = {}) and setup pairing manually using ConstraintMapping. Everyting stil works, except for message interpolation.
Log now contains kinda cryptic message:
Expression variables have been defined for constraint interface whatever.SomeValidation while Expression Language is not enabled.
All of that while I'm literary using the same code as one mentioned here:
https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#_custom_contexts
to disableDefaultConstraintViolation and register custom one.
Any ideas what can cause that?
Given a function 'plugin_update' that would take a parameter $version, how can I pass a value to this method using the following syntax with the add_action method (as the method is within a class):
add_action('plugins_loaded',array('test-app-class','plugin_update'));
I have tried several variations that didn't seem to work. Any advice appreciated!
Short answer: No.
Let me explain why.
WordPress Event Engine Explanation
The add_action construct allows you to register a callback to an event. In your case, the event is plugins_loaded. The event is then fired when the construct do_action() or do_action_ref_array.
What happens when the event fires? WordPress Core does the following:
Assembles the arguments, if any are passed
Sorts the event registry table
Calls each of the registered callbacks in order (as determine by the priority number and when it loaded into the registry), passing the arguments (if any)
The arguments that are passed to each callback is determined by the firing construct. Huh? The do_action() specifies if any arguments will be passed to the callbacks. Then each callback can declare if it wants them or not.
Why Can't You Pass the Version?
The plugins_loaded event does not pass arguments. Your callback cannot specify parameters that are not passed from the firing construct.
In other words, the code that does the `do_action’ determines the arguments that your function can choose to accept and use.
Why? Because the do_action is the main firing mechanism. It says "Hello plugins and themes, I'm running now. If you are registered to me, then I'll call you tomrun too. And I might send you some parameters too."
Options for You
How do you get the version into to your callback?
You have many choices:
storing it in the database if it's dynamic (will change)
store it as an environmental variable and load it
store it as a configuration parameter and load it
As your using OOP, I'd advise injecting it when instantiating the object. I typically inject the dynamic configuration when I create the objects.
Reference
Here is a link to the Core code where WordPress fires do_action( 'plugins_loaded' );: click here to view on GitHub. Notice, there are no arguments being declared, which means none will be passed.
How to customize segment using query string or cookie in Adobe CQ5.6?
My requirement as follows:
I wanted to target querystring parameters in Segment which is added in my Experience, Teaser, Promotion, Voucher for owned site.
Thanks in advance.
You can define your own segment at outlined here: https://docs.adobe.com/docs/en/cq/5-6-1/administering/segmentation.html#Defining%20a%20New%20Segment
In step 6 where you edit the segment, you need to supply a JavaScript expression that will resolve to a boolean, true or false. You can put any JavaScript expression here that meets your need, so you can include script that will have a complex expression if you want. But rather than write a complex JavaScript expression here, it would be better to write JavaScript that exposes a function which returns true or false and then include that JavaScript function on your pages via a client library. Then, in the segment, you can simply invoke the function rather defined in your client library than try to write a complex expression.
As long as the JavaScript expression defined in the segment evaluates to true/false, the segment will be usable.
Without your own JavaScript you can easily fetch query string values of look at cookies. See these other questions for details on that:
What is the shortest function for reading a cookie by name in JavaScript?
How can I get query string values in JavaScript?
This is a somewhat philosophical issue. I have a .net (but could be any platform) based helper library that parses query string values. Take for example a variable that returns an Int32: my framework has an option that specifies whether this value is required or optional. If it is required but not provided, the framework throws an exception. If it is optional and not specified, it returns a null.
Now an edge case has come up based on users hacking (in a good way) our urls. If they specify a variable with either an invalidly formatted Int32 ("&ID=abc") or provide the variable but not specify a value ("&id="), should the framework throw an exception or should it return a null?
Part of me feels that invalid variables or formats should return a null. It might be valid to argue that even if the parameter is optional, an invalidly formatted query string or value should still throw an exception.
Thoughts?
Since this is philophical ...
On something like an ID, I would agree with Shawn that it is a 404, especially if you are thinking in terms of state. There is no object, so not found. But, ID may not tie directly to a resource in all cases.
If the item is truly optional, a null is okay. But optional should mean "if present it makes the call more specific" in this case and there should always be a fallback. I don't see this in ID, unless the ID is keyed to an optional part of the page.
In the long run, I think you should look at the business reason for the page and what each variable means.
I believe that if a variable is optionaly, providing the variable but not specifying the value is equivalent to ommitting the variable itself. In this case, returning null seems OK.
However, providing an invalidly formatted value ought to cause an Exception, since the intent was to provide a value. In this case the user ought to be notified through some sort of validation mechanism.
A HttpException of 404 (Not Found). Your web application framework should know how to catch these errors and redirect to the proper page.
This is actually a not found error because the resources that the ID is pointing to does not exist.
I suspect there's no "right" answer to your question. If I were a developer using your library, I would expect/hope that the public API would include in its code comments, a description of how the function behaves when the URL param includes bad (wrong type) data.
You might also be able to craft your public API to get the best of both worlds: .NET seems to have adopted the "Parse" / "TryParse" approach in many places. If I'm the caller and I want the function to throw if given invalid data, I call Parse(). If I don't want it to throw, I call TryParse(). In my opinion, that is a nice pattern to follow with your API as well.