2017-10-02 7 views
1

gun 0.8.7、Node.js-to-Node.js、ブラウザなし。アイテムが更新された場合、セット上のマップは起動されません。

ノードが正常に作成され、tasksに追加されたリスナー側

const Gun = require('gun'); 

const gun = new Gun({peers:['http://localhost:8080/gun']}); 
const tasks = gun.get('tasks'); 
tasks.map().val(function (task) { 
    console.log('task', task); 
}); 

a2task { _: 
    { '#': 'watcher/123', 
    '>': { id: 1506959623558, type: 1506959623558, stat: 1506959623558 } }, 
    id: '123', 
    type: 'skeleton', 
    stat: { '#': 'j8acunbf70NblJptwXWa' } } 
task { _: 
    { '#': 'watcher/456', 
    '>': 
     { id: 1506959623579.002, 
     type: 1506959623579.002, 
     stat: 1506959623579.002 } }, 
    id: '456', 
    type: 'snowmann', 
    stat: { '#': 'j8acunbv03sor9v0NeHs7cITj' } } 
task { _: 
    { '#': 'watcher/789', 
    '>': 
     { id: 1506959623581.002, 
     type: 1506959623581.002, 
     stat: 1506959623581.002 } }, 
    id: '789', 
    type: 'moose', 
    stat: { '#': 'j8acunbx03sorM0hWZdQz0IyL' } } 

.map評価の結果があります。しかし、ある

const Gun = require('gun'); 
const _ = require('lodash'); 
require("gun/lib/path"); 

const gun = new Gun({peers:['http://localhost:8080/gun', 'http://localhost:8081/gun']}); 

const watchers = [ 
    { 
    id: '123', 
    type: 'skeleton', 
    stat: { 
     num: 0 
    } 
    }, 
    { 
    id: '456', 
    type: 'snowmann', 
    stat: { 
     num: 0 
    } 
    }, 
    { 
    id: '789', 
    type: 'moose', 
    stat: { 
     num: 0 
    }, 
    } 
]; 

const tasks = gun.get('tasks'); 

_.forEach(watchers, function (watcher) { 
    let task = gun.get(`watcher/${watcher.id}`).put(watcher); 
    tasks.set(task); 
}); 

を設定オンの場合は結果がありません更新されたプロパティのe:

_.forEach(watchers, function (watcher) { 
    gun.get(`watcher/${watcher.id}`).put({ 
    stat: { 
     num: 1 
    } 
    }); 

なぜですか?ここで

は、あなたがそのレベルをマッピングしていないので、それは何のアップデートを取得していないhttps://github.com/sergibondarenko/shared-schedule

答えて

1

でプレイするためのコードです。 'stat'は既にオブジェクトであるプロパティなので、変更はありません。

tasks.map().map().val(function (task_stat) { 
    console.log('task stat', task_stat); 
}); 
+0

これは動作しません。アップデートはありません。 – trex

+0

@trexはこれがおそらく私がv0.8.9で修正したことがわかったバグに関係していたでしょうか?今すぐやり直してみてください。 – marknadal

関連する問題