Skip to content

Commit 63ee6d0

Browse files
committed
👈♒ Updated at https://danielx.net/editor/
1 parent d3e5667 commit 63ee6d0

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

lib/iframe-app.coffee

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ state that can respond to messages from the OS.
1313
1414
###
1515

16+
{Observable} = require "ui"
1617
Postmaster = require "postmaster"
1718

19+
ObservableObject = require "./observable-object"
20+
1821
{version} = require "../pixie"
1922

2023
module.exports = (opts={}) ->
@@ -69,7 +72,10 @@ module.exports = (opts={}) ->
6972

7073
# TODO: Set menu bar from within app
7174

72-
# This receives and dispatches the messages from the iframe
75+
# This receives messages from the iframe and dispatches messages to the iframe
76+
# Apps within ZineOS can communicate to each other via the application object,
77+
# while within the iframe they communicate through this postmaster degegate to
78+
# their specific application or the system.
7379
Object.assign postmaster,
7480
remoteTarget: ->
7581
frame.contentWindow
@@ -106,7 +112,13 @@ module.exports = (opts={}) ->
106112
height: height
107113
iconEmoji: iconEmoji
108114

115+
signals = ObservableObject()
116+
109117
Object.assign application,
118+
# Observable fn that returns an array of [key, Observable(value)] items
119+
signals: signals
120+
# Expose an observable property that can be updated from within the iframe
121+
setSignal: signals.set
110122
exit: ->
111123
# TODO: Prompt unsaved, etc.
112124
setTimeout ->

lib/observable-object.coffee

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{Observable} = require "ui"
2+
3+
# An object that has an observable fn of entries of [key, Observable(value)] items
4+
module.exports = ->
5+
entries = {}
6+
update = Observable 0
7+
8+
get: (name) ->
9+
unless entries[name]?
10+
entries[name] ?= Observable()
11+
update.increment()
12+
13+
return entries[name]
14+
15+
set: (name, value) ->
16+
if entries[name]?
17+
entries[name](value)
18+
else
19+
entries[name] ?= Observable value
20+
update.increment()
21+
22+
return value
23+
24+
remove: (name) ->
25+
unless entries[name]?
26+
throw new Error "Can't remove #{name}, does not exists"
27+
28+
delete entries[name]
29+
update.increment()
30+
31+
return true
32+
33+
entries: Observable ->
34+
update() # Trigger a recomputation when entries update
35+
36+
Object.keys(entries).map (name) ->
37+
value = entries[name]
38+
[name, value]

system/applications.coffee

+5
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ module.exports = (I, self) ->
192192
icon: "📖"
193193
associations: ["md", "html"]
194194
src: "https://danielx.whimsy.space/danielx.net/dr-wiki/"
195+
}, {
196+
name: "FXZ Edit"
197+
icon: "📈"
198+
associations: ["fxx", "fxz"]
199+
src: "https://danielx.whimsy.space/danielx.net/fxz-edit/"
195200
}, {
196201
name: "First"
197202
icon: " 1️⃣"

test/lib/observable-object.coffee

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ObservableObject = require "/lib/observable-object"
2+
3+
describe "ObservableObject", ->
4+
it "should observe properties", ->
5+
o = ObservableObject()
6+
7+
o.get("cool").observe (v) ->
8+
console.log "cool", v
9+
10+
o.entries.observe console.log
11+
o.set "cool", "wat"
12+
o.set "jawsome", "2jawsome"
13+
o.remove "cool"

0 commit comments

Comments
 (0)