Skip to content

Commit 6a69ff5

Browse files
committed
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core into gh-pages
2 parents 029be84 + 7b5988a commit 6a69ff5

File tree

5 files changed

+163
-5
lines changed

5 files changed

+163
-5
lines changed

doc/journal/2020-12-18.md/index.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## 2020-12-18
2+
*Author: @JensLincke*
3+
4+
5+
## Example #Connection Workspace
6+
7+
```javascript
8+
import Connection from "src/components/halo/Connection.js"
9+
10+
var a, b, connection;
11+
12+
(async () => {
13+
a = <div>A</div>
14+
b = <div>B</div>
15+
connection = new Connection(a, "foo", b, "bar")
16+
connection.activate();
17+
18+
await lively.sleep(0) // it seems to take time...
19+
20+
a.foo = "hello3"
21+
22+
await lively.sleep(0) // it seems to take time...
23+
24+
25+
if (b.bar != a.foo) {
26+
lively.warn("foo !== bar")
27+
} else {
28+
lively.success("foo == bar")
29+
}
30+
})()
31+
```
32+
33+
MD*/

src/client/contextmenu.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Favorites from "src/client/favorites.js"
2121
import { applicationFolder } from 'src/client/vivide/utils.js';
2222
import { createView } from 'src/client/vivide/scripts/loading.js';
2323
import SearchRoots from "src/client/search-roots.js"
24+
import Connection from "src/components/halo/Connection.js";
2425

2526
// import lively from './lively.js'; #TODO resinsert after we support cycles again
2627

@@ -330,6 +331,19 @@ export default class ContextMenu {
330331

331332
// #important
332333
static worldMenuItems(worldContext) {
334+
335+
let connections = []
336+
Connection.allConnections.forEach(connection => {
337+
connections.push(connection)
338+
})
339+
let existingConnectionsMenu = connections.map(connection => [connection.getFullLabel(),
340+
async () => {
341+
let editor = await lively.openComponentInWindow('lively-connection-editor')
342+
lively.setExtent(editor.parentElement, lively.pt(800, 50))
343+
editor.setConnection(connection)
344+
}]);
345+
346+
333347
var items = [
334348
["Workspace", evt => {
335349
this.hide();
@@ -611,6 +625,13 @@ export default class ContextMenu {
611625
}
612626
}]]), undefined, '<i class="fa fa-window-restore" aria-hidden="true"></i>'
613627
],
628+
[
629+
"Debug", [
630+
['Connections', existingConnectionsMenu, '', '<i class="fa fa-arrow-right" aria-hidden="true"></i>']
631+
632+
], undefined, '<i class="fa fa-bug" aria-hidden="true"></i>'
633+
],
634+
614635
["View", [
615636
["Reset View", () => ViewNav.resetView(),
616637
"",'<i class="fa fa-window-restore" aria-hidden="true"></i>'],

src/components/halo/Connection.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export default class Connection {
2222
}
2323

2424
constructor(source, sourceProperty, target, targetProperty, isEvent) {
25-
debugger
2625
this.id = Connection.nextId();
2726
window.allConnections.add(this);
2827

@@ -34,16 +33,17 @@ export default class Connection {
3433
this.isActive = false
3534
this._eventListener = evt => this.connectionFunction(evt)
3635
this._targetProperty = this.cleanProperty(this._targetProperty)
36+
37+
3738
if(isEvent){
38-
if (this.targetIsFunction()) {
39-
this.modifyingCode =
39+
if (this.targetIsFunction()) {
4040
this.modifyingCode =
4141
`(target, event) => {
4242
target.${this._targetProperty}(event);
4343
}`;
4444
} else {
45-
`(target, event) => {
46-
target.${this._targetProperty} = 42;
45+
this.modifyingCode = `(target, event) => {
46+
target.${this._targetProperty} = event;
4747
}`;
4848
}
4949

@@ -322,6 +322,17 @@ export default class Connection {
322322
getLabel() {
323323
return this._sourceProperty + "⇨" + this._targetProperty
324324
}
325+
326+
getFullLabel() {
327+
try {
328+
return lively.elementToCSSName(this.getSource()) + " " + this._sourceProperty +
329+
"⇨" + lively.elementToCSSName(this.getTarget()) + " "+ this._targetProperty
330+
} catch(e) {
331+
return this.getLabel()
332+
}
333+
334+
}
335+
325336

326337
setLabel(string) {
327338
this.label = string // not used...

src/components/widgets/lively-code-mirror.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ export default class LivelyCodeMirror extends HTMLElement {
941941
}
942942

943943
set value(text) {
944+
if (text === undefined) text = ""
944945
if (this.editor) {
945946
this.editor.setValue(text)
946947
} else {

test/bindings-test.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import {expect} from 'src/external/chai.js'
44
import Bindings from "src/client/bindings.js"
5+
import Connection from "src/components/halo/Connection.js"
56

67
/*MD # [Bindings](edit://src/client/bindings.js) Test
78
@@ -37,3 +38,94 @@ describe('Bindings', function() {
3738
});
3839
})
3940
});
41+
42+
43+
// The Halo based Connections
44+
45+
describe('Connections', function() {
46+
47+
describe('connect', function() {
48+
it('connects event with property', async function() {
49+
var a = <div>A</div>
50+
var b = <div>B</div>
51+
var connection = new Connection(a, "click", b, "foo", true)
52+
connection.activate();
53+
await lively.sleep(0) // it seems to take time...
54+
55+
a.dispatchEvent(new Event("click"))
56+
57+
await lively.sleep(0) // it seems to take time...
58+
59+
expect(b.foo).to.not.be.undefined();
60+
});
61+
62+
it('connects event with function', async function() {
63+
var a = <div>A</div>
64+
var b = <div>B</div>
65+
b.func = function(v) { this.bar = v}
66+
67+
var connection = new Connection(a, "click", b, "func", true)
68+
69+
connection.activate();
70+
await lively.sleep(0) // it seems to take time...
71+
72+
a.dispatchEvent(new Event("click"))
73+
74+
await lively.sleep(0) // it seems to take time...
75+
76+
expect(b.bar).to.not.be.undefined();
77+
});
78+
79+
80+
81+
it('connects property with property', async function() {
82+
var a = <div>A</div>
83+
var b = <div>B</div>
84+
var connection = new Connection(a, "foo", b, "bar")
85+
connection.activate();
86+
await lively.sleep(0) // it seems to take time...
87+
88+
a.foo = "hello"
89+
90+
await lively.sleep(0) // it seems to take time...
91+
92+
expect(b.bar).to.equal("hello");
93+
});
94+
95+
it('connects property with function', async function() {
96+
var a = <div>A</div>
97+
var b = <div>B</div>
98+
b.func = function(v) { this.bar = v}
99+
100+
var connection = new Connection(a, "foo", b, "func")
101+
102+
connection.activate();
103+
await lively.sleep(0) // it seems to take time...
104+
105+
a.foo = "hello"
106+
107+
await lively.sleep(0) // it seems to take time...
108+
109+
expect(b.bar).to.equal("hello");
110+
});
111+
112+
113+
it('connects style attribute with style attribute', async function() {
114+
var a = <div>A</div>
115+
var b = <div>B</div>
116+
117+
var connection = new Connection(a, "style.width", b, "style.width")
118+
connection.activate();
119+
120+
await lively.sleep(0) // it seems to take time...
121+
122+
a.style.width = "50px"
123+
124+
await lively.sleep(0) // it seems to take time...
125+
126+
expect(b.style.width).to.equal("50px");
127+
});
128+
})
129+
});
130+
131+

0 commit comments

Comments
 (0)