wiki-plugin-mech 0.1.22 → 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/client/mech.js +59 -6
  2. package/package.json +1 -1
package/client/mech.js CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  (function() {
3
-
3
+ "use strict"
4
4
  const uniq = (value, index, self) => self.indexOf(value) === index
5
5
 
6
6
  function expand(text) {
@@ -37,7 +37,7 @@
37
37
  const unique = Math.floor(Math.random()*1000000)
38
38
  const block = (more,path) => {
39
39
  const html = []
40
- for (part of more) {
40
+ for (const part of more) {
41
41
  const key = `${unique}.${path.join('.')}`
42
42
  part.key = key
43
43
  if('command' in part)
@@ -272,7 +272,7 @@
272
272
  }
273
273
 
274
274
  function walk_emit ({elem,command,args,state}) {
275
- if(!('neighborhood' in state)) return trouble(elem,`FILE expects state.neighborhood, like from NEIGHBORS.`)
275
+ if(!('neighborhood' in state)) return trouble(elem,`WALK expects state.neighborhood, like from NEIGHBORS.`)
276
276
  inspect(elem,'neighborhood',state)
277
277
  const steps = walks(state.neighborhood)
278
278
  const aspects = steps.filter(({graph})=>graph)
@@ -592,7 +592,7 @@
592
592
  .map(info => info.domain)
593
593
  .filter(uniq)
594
594
  const any = array => array[Math.floor(Math.random()*array.length)]
595
- console.log(infos)
595
+ if(state.debug) console.log(infos)
596
596
  const items = [
597
597
  {type:'roster', text:"Mech\n"+sites.join("\n")},
598
598
  {type:'activity', text:`ROSTER Mech\nSINCE 30 days`}]
@@ -615,6 +615,57 @@
615
615
  state.items = items
616
616
  }
617
617
 
618
+ function listen_emit({elem,command,args,state}) {
619
+ if (args.length < 1) return trouble(elem,`LISTEN expects argument, an action.`)
620
+ const topic = args[0]
621
+ let recent = Date.now()
622
+ let count = 0
623
+ const handler=listen
624
+ handler.action = 'publishSourceData'
625
+ handler.id = elem.id
626
+ window.addEventListener("message", listen)
627
+ $(".main").on('thumb', (evt, thumb) => console.log('jquery',{evt, thumb}))
628
+ elem.innerHTML = command + ` ⇒ ready`
629
+
630
+ // window.listeners = (action=null) => {
631
+ // return getEventListeners(window).message
632
+ // .map(t => t.listener)
633
+ // .filter(f => f.name == 'listen')
634
+ // .map(f => ({action:f.action,elem:document.getElementById(f.id),count:f.count}))
635
+ // }
636
+
637
+
638
+
639
+ function listen(event) {
640
+ console.log({event})
641
+ const {data} = event
642
+ if (data.action == 'publishSourceData' && (data.name == topic || data.topic == topic)) {
643
+ count++
644
+ handler.count = count
645
+ if(state.debug) console.log({count,data})
646
+ if(count<=100){
647
+ const now = Date.now()
648
+ const elapsed = now-recent
649
+ recent = now
650
+ elem.innerHTML = command + ` ⇒ ${count} events, ${elapsed} ms`
651
+ } else {
652
+ window.removeEventListener("message", listen)
653
+ }
654
+ }
655
+ }
656
+ }
657
+
658
+ function message_emit({elem,command,args,state}) {
659
+ if (args.length < 1) return trouble(elem,`MESSAGE expects argument, an action.`)
660
+ const topic = args[0]
661
+ const message = {
662
+ action: "publishSourceData",
663
+ topic,
664
+ name: topic,}
665
+ window.postMessage(message,"*")
666
+ elem.innerHTML = command + ` ⇒ sent`
667
+ }
668
+
618
669
 
619
670
  // C A T A L O G
620
671
 
@@ -641,7 +692,9 @@
641
692
  GET: {emit:get_emit},
642
693
  DELTA: {emit:delta_emit},
643
694
  ROSTER: {emit:roster_emit},
644
- LINEUP: {emit:lineup_emit}
695
+ LINEUP: {emit:lineup_emit},
696
+ LISTEN: {emit:listen_emit},
697
+ MESSAGE: {emit:message_emit}
645
698
  }
646
699
 
647
700
 
@@ -752,7 +805,7 @@
752
805
  const start = rand(here)
753
806
  done.add(start.slug)
754
807
  node(start)
755
- for (n=5;n>0;n--) {
808
+ for (let n=5;n>0;n--) {
756
809
  try {
757
810
  const slugs = links(nid)
758
811
  const slug = rand(slugs)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-mech",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
4
  "description": "Federated Wiki - Mechanism Scripting Plugin",
5
5
  "keywords": [
6
6
  "mech",