How to give names to MobX flows - mobx

How do I give a name to my flows?
I currently see messages in the console (using dev tools) like:
action '<unnamed flow> - runid: 3 - init'
index.js:1 action '<unnamed flow> - runid: 3 - yield 0'
My code (in typescript):
fetchMetricData = flow( function * (this: MetricDataStore) {
const responseJson:IMetrics[] = yield Http.post("/metrics");
this.metrics = responseJson;
});

According to following text found in MobX Api Reference · MobX page:
Tip: it is recommended to give the generator function a name, this is the name that will show up in dev tools and such
Unfortunately, this is the only way to set the name (I use LiveScript and can't set names to function expressions while defining it).
In your case, you can turn your unnamed function expression into a named one. If you ever face another situation where you can't, you could also use Object.defineProperty(myFunction, 'name', {value: 'myExplicitName'}).
You can find the culprit in the code: mobx/flow.ts at master · mobxjs/mobx.

Related

Terraform: How Do I Setup a Resource Based on Configuration

So here is what I want as a module in Pseudo Code:
IF UseCustom, Create AWS Launch Config With One Custom EBS Device and One Generic EBS Device
ELSE Create AWS Launch Config With One Generic EBS Device
I am aware that I can use the 'count' function within a resource to decide whether it is created or not... So I currently have:
resource aws_launch_configuration "basic_launch_config" {
count = var.boolean ? 0 : 1
blah
}
resource aws_launch_configuration "custom_launch_config" {
count = var.boolean ? 1 : 0
blah
blah
}
Which is great, now it creates the right Launch configuration based on my 'boolean' variable... But in order to then create the AutoScalingGroup using that Launch Configuration, I need the Launch Configuration Name. I know what you're thinking, just output it and grab it, you moron! Well of course I'm outputting it:
output "name" {
description = "The Name of the Default Launch Configuration"
value = aws_launch_configuration.basic_launch_config.*.name
}
output "name" {
description = "The Name of the Custom Launch Configuration"
value = aws_launch_configuration.custom_launch_config.*.name
}
But how the heck do I know from the higher area that I'm calling the module that creates the Launch Configuration and Then the Auto Scaling Group which output to use for passing into the ASG???
Is there a different way to grab the value I want that I'm overlooking? I'm new to Terraform and the whole no real conditional thing is really throwing me for a loop.
Terraform: How to conditionally assign an EBS volume to an ECS Cluster
This seemed to be the cleanest way I could find, using a ternary operator:
output "name {
description = "The Name of the Launch Configuration"
value = "${(var.booleanVar) == 0 ? aws_launch_configuration.default_launch_config.*.name : aws_launch_configuration.custom_launch_config.*.name}
}
Let me know if there is a better way!
You can use the same variable you used to decide which resource to enable to select the appropriate result:
output "name" {
value = var.boolean ? aws_launch_configuration.custom_launch_config[0].name : aws_launch_configuration.basic_launch_config[0].name
}
Another option, which is a little more terse but arguably also a little less clear to a future reader, is to exploit the fact that you will always have one list of zero elements and one list with one elements, like this:
output "name" {
value = concat(
aws_launch_configuration.basic_launch_config[*].name,
aws_launch_configuration.custom_launch_config[*].name,
)[0]
}
Concatenating these two lists will always produce a single-item list due to how the count expressions are written, and so we can use [0] to take that single item and return it.

Why is yadcf custom_filter not working?

Fiddle: https://codepen.io/MBaas/pen/rpZZzd
I have a Datatable about newspapers endorsements for presidential candidates that I want to filter on the party - a value that is not contained in the table (I have shortcodes "D" or "R" in the table but would like to use text "Democrat" or "Republican" in the UI).
This may have once worked (I think it did) - but after upgrading to beta 0.9.1 it stopped. Possibly a bug in the beta - or possibly an undetected bug in my code?
My fn:
function myCustomFilterFunction(filterVal,columnVal,rowValues,stateVal)
{
console.log(rowValues);
console.log(filterVal+'/'+columnVal);
if (columnVal === '') { return true;}
return -1 < columnVal.search(filterVal);
}
I had added the log for debugging purposes and it produced this output (excerpt):
["Wisconsin State Journal", "2016", "Clinton", "", "", "", ""]
"D/"
I was surprised to see columnVal being empty. That explained filtering not working, and it being empty can be explained by looking at rowValues. But given that the source-data was defined in JSON as
["Wisconsin State Journal",2016,"Clinton","http:\/\/host.madison.com\/wsj\/opinion\/editorial\/our-endorsement-hillary-clinton-america-must-get-this-right\/article_b526fe64-c2ca-5e3d-807a-0ef4ae23a4d5.html","","","D"]
this is odd. Could it be related to the fact that the column is not visible?
You should make column containing party short code searchable with searchable: true option otherwise your custom filtering function won't work.
For example:
{"searchable":true, "title":"Party (Shortcode)", "visible":true}
See updated example for code and demonstration.

Vue.js root variable

I am working on my own directory for my purchases of cryptocurrencies.
I am getting prices of BTC, ETH, and LTC via API, then I created a component for each of my punched coin, so then I want to calculate current price (ownedCoins * currentPrice).
So in my $root I have { eth: 324.233, btc: 2211.43, ltc: 41.341 }
Here is where I want to calculate it:
self.eur = response.data.sum[0].quantity * this.$root.ltc;
But I want to make this dynamic, so what I want to do is to create a dynamic variable. Something like that: self.eur = response.data.sum[0].quantity * this.$root.{this.coinName};
How would I do that?
I would read the State Management part of the VueJS docs then checkout the Vuex docs. Once your data store get even mildly more complex your method of managing it with your sample code will become overwhelming.
Your question doesn't have anything to do with vue, but just plain javascript. To access object variables in javascript you have 2 ways, using the dot notation or bracket notation (I call it array notation):
const car = { wheels: 4, seats: 5, horsepower: 145 };
console.log(car.wheels);
console.log(car['wheels']); //same result
So
this.$root[this.coinName];
will give you the result you are looking for.

How to pass variable to groovy code in Intellij IDEA live templates groovy script?

I have a groovyScript in my Intellij IDEA live template, like this :
groovyScript("D:/test.groovy","", v1)
on my D:/test.groovy i have a code like this:
if ( v1 == 'abc') {
'abc'
}
Now I want to pass v1 variable into test.groovy ,can any one help me how can I do this?
For exemplification purposes I made a live template which is printing a comment with the current class and current method.
This is how my live template is defined:
And here is how I edited the variableResolvedWithGroovyScript variable:
The Expression for the given variable has the follwing value:
groovyScript("return \"// Current Class:\" + _1 + \". Current Method:\"+ _2 ", className(),methodName())
As you can see, in this case the _1(which acts like a variable in the groovy script) takes the value of the first parameter which is the class name, and the _2 takes the value of the
second parameter which is the method name. If another parameter is needed the _3 will be used in the groovy script to reference the given parameter.
The arguments to groovyScript macro are bound to script variables named _1, _2 etc. This is also described at groovyScript help at Edit Template Variables Dialog / Live Template Variables.
I found a solution.
I was needing to calculate a CRC32 of the qualified class name using live models
I used it like this:
groovyScript("
def crc = new java.util.zip.CRC32().with { update _1.bytes; value };
return Long.toHexString(crc);
", qualifiedClassName())
then the result is
Based on the documentation, your variables are available as _1, _2, etc. Please note that variables are passed without dollar signs (so only v1 instead of $v1$)
So your test script should look like
if ( _2 == 'abc') {
'abc'
}

Passing options to JS function with Amber

I'm trying to write the equivalent of:
$( "#draggable" ).draggable({ axis: "y" });
in Amber smalltalk.
My guess was: '#draggable' asJQuery draggable: {'axis' -> 'y'} but that's not it.
Not working on vanilla 0.9.1, but working on master at least last two months ago is:
'#draggable' asJQuery draggable: #{'axis' -> 'y'}
and afaict this is the recommended way.
P.S.: #{ 'key' -> val. 'key2' -> val } is the syntax for inline creation of HashedCollection, which is implemented (from the aforementioned two-month ago fix) so that only public (aka enumerable) properties are the HashedCollection keys. Before the fix also all the methods were enumerable, which prevented to use it naturally in place of JavaScript objects.
herby's excellent answer points out the recommended way to do it. Appearently, there is now Dictionary-literal support (see his comment below). Didn't know that :-)
Old / Alternate way of doing it
For historical reasons, or for users not using the latest master version, this is an alternative way to do it:
options := <{}>.
options at: #axis put: 'y'.
'#draggable' asJQuery draggable: options.
The first line constructs an empty JavaScript object (it's really an JSObjectProxy).
The second line puts the string "y" in the slot "axis". It has the same effect as:
options.axis = "y"; // JavaScript
Lastly, it is invoked, and passed as a parameter.
Array-literals vs Dictionaries
What you were doing didn't work because in modern Smalltalk (Pharo/Squeak/Amber) the curly-brackets are used for array-literals, not as an object-literal as they are used in JavaScript.
If you evaluate (print-it) this in a Workspace:
{ #elelemt1. #element2. #element3 }.
You get:
a Array (#elelemt1 #element2 #element3)
As a result, if you have something that looks like a JavaScript object-literal in reality it is an Array of Association(s). To illustrate I give you this snippet, with the results of print-it on the right:
arrayLookingLikeObject := { #key1 -> #value1. #key2 -> #value2. #key3 -> #value3}.
arrayLookingLikeObject class. "==> Array"
arrayLookingLikeObject first class. "==> Association"
arrayLookingLikeObject "==> a Array (a Association a Association a Association)"
I wrote about it here:
http://smalltalkreloaded.blogspot.co.at/2012/04/javascript-objects-back-and-forth.html