What is the current `map()` doing? - gun

( Gun.version 0.9.6 )
Given the following data structure
{
lights:{
1:{
state:{
on:true,
color:'red',
br:254
}
},
2:{
state:{
on:true,
color:'red',
br:254
}
},
3:{
state:{
on:true,
color:'red',
br:254
}
}
}
}
I want to turn the lights on/off at the same time.
gun.get('lights').val(cb) does give me {1:{...},2:{...},3:{...}} and gun.get('lights').path('1.state.on').put(false); works perfect.
I thought that by doing gun.get('lights').map().path('1.state.on').put(false) it would 'map' over all lights but instead it only changes the first light.
Question: How do i turn on/off all the lights ?

#stef-de-vries , you've spotted an important TODO bug in gun's source code!
Currently (v0.9.6), put does not work with map() commands. I think it only picks the first item (which may be random) and then turns it off.
This is bad, and needs to be addressed.
For now, the work around is to probably do something like:
gun.get('lights').map().path('state.on').val(function(){
this.put(false);
});
Which is ugly.

Hmm.. okay, but it fails on gun.get('lights').map().val(cb) also if i run it the second time.
Solved my problem with the each() module
gun.get('lights').each(node=>{
gun.get(node._['#']).path('state.on').put(true)
})

Related

$substr doesnt work on mongodb compass community

I have a collection and i want to show like some characteres from "categoria" which is inside "Problema", but it keeps giving me this error, and i have searched alot and i think everything is correct, any help?
In order to use $substr you will need to use an aggregation
I tried the aggregation tool in Compass, but it is not clear to me.
However, I tried this aggregation with one collection:
db.getCollection('products').aggregate(
[
{
$project:
{
tex: { $substr: ["$name",2,7] }
}
}
])

React-native sound delay issue

This is just general question. I want to make drums-like app but i have sound delay. Maybe someone tried some other package(s) and did some magic, I used react-native-sound and react-native-video since they are most popular and not outdated like others. This is code sample:
new Sound(`${filename}.mp3`, Sound.MAIN_BUNDLE, error => {
if (error) {
return;
} else {
audio.play(() => {
audio.release();
});
}
});
There are other libraries, maybe outdated, but i am looking for any input to make it better, we did handler with onPressIn to make it slightly faster but still big delay:
<TouchableOpacity onPressIn={handleOpenPress}>
If this fails I will try to make another library, but I fear it will have the same delay. For some reason this repo works very fast: https://github.com/dwicao/react-native-drum-kit. I used same code and made even a list with prepared sounds to be used like soundList[i++ % 10].play() but still no effect.

MithrilJS Hyperscript

m("div", {
onclick: function(e) {
console.log(e);
},
}, "Test")
Hello, i would like to know if having an event handler such as the one above creates a new function on Mithril redraw? I want to avoid performance issues.
It will be recreated on each redraw. The perf impact is generally negligible.
https://jsperf.com/create-function-vs-reference isn't an exact test, but hopefully provides a rough idea of the difference.
Always profile though! If the function creation is your bottleneck abstracting it out would be an easy fix.

Rally grid color rows based on model

I have a rallygrid that is configured to display two models: PortfolioItem/Feature and PortfolioItem/Rollup. I want to color them in the grid to differentiate them. I am not garunteed that they will alternate in the grid, or anything like that. I just want to apply a subtle color to the rollups to differentiate them visually.
Can anyone think of an easy way to achieve this?
I have tried:
viewConfig: {
getRowClass: function(record, index, rowParams, store) {
console.log('record',record); // nothing logged in console
console.log('index',index);
return 'colorCodeGrid'; // class never added
}
},
[EDIT]
viewConfig: {
stripeRows: false, // rows are no longer striped
getRowClass: function(record, index, rowParams, store) {
console.log('record',record); // still nothing logged in console
console.log('index',index);
return 'colorCodeGrid'; // class never added
}
},
It is strange to me that the viewConfig does correctly un-stripe the rows, but the getRowClass never gets called. I thought maybe just the viewConfig as a whole was not being used in the case of a rallygrid.
Your approach above with the viewConfig should work- I am going to file a defect on this. The root cause is that the Rally.ui.grid.GridView is blowing away the getRowClass function in its constructor (for internal browser testing purposes- ugghh) rather than checking if there was one supplied and calling that as well.
You can see it the source for the constructor here: https://developer.help.rallydev.com/apps/2.0rc1/doc/source/GridView.html#Rally-ui-grid-GridView
You should be able to work around it by just re-overriding the function before the view is rendered.
[EDIT by asker]
Added the following to the grid, and it worked:
listeners: {
beforerender: function(cmp) {
console.log('beforerender');
console.log('view',cmp);
cmp.view.getRowClass = function(record, index, rowParams, store) {
console.log('record',record); // still nothing logged in console
console.log('index',index);
return 'colorCodeGrid'; // class never added
};
}
},
UPDATE:
I just fixed this in the nightly build, so this should no longer be an issue in public sdk builds beginning with the next public release after 2.0rc2.

My Ember's controller's properties are being literally echoed

I've been during a while working with Ember.js. Now I'm getting a weird behaviour that I cannot fix. Is not the first time I experience it, but in previous occasions I figured it out after making little changes. But now, I really have no idea what's causing the conflict. The issue is occuring in Controllers. I have this ridiculously simple controller, just for testing:
App.AppColleaguesController = Ember.ArrayController.extend
(
{
needs: ['app'],
aNumber: function()
{
return this.get('controllers.app.personId');
}
}
);
Of course, that property is defined on the AppController:
App.AppController = Ember.ArrayController.extend
(
{
loggedIn: false,
personId: -1,
personName: '',
location: '',
logOut: function()
{
if (window.confirm("Do you want log out?"))
{
this.set('loggedIn', false);
this.set('personId', -1);
this.set('personName', '');
this.set('location', '');
this.send('goToLogin');
}
}
}
);
In my template, I'm getting this result:
... This is a number: function () { return
this.get('controllers.app.personId'); } ...
My template is as straightforward as this:
...
This is a number: *{{aNumber}}*
{{debug}}
{{log aNumber}}
...
The debugging statements in my template are showing me this in Firebug console:
...
Transitioned into 'app.colleagues'
function()
...
So, is like the function is literally echoed, not "interpreted". In fact I'm getting this sort of problem in a couple more of controllers, but the rest of them (they are a lot, like 8 or 10 controllers) are working nice. Do you have any idea about the problem? Is my mistake, or maybe an Ember issue?
Thanks a lot in advance! I hope you can help me.
You forgot the .property after the function. This is needed by Ember to indicate that a function is a computed property.
aNumber: function() {
return this.get('controllers.app.personId');
}.property('app.personId')