enigmatic 0.21.2 → 0.21.4

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.
package/enigmatic.js CHANGED
@@ -101,7 +101,8 @@ if (window.components) {
101
101
  }
102
102
 
103
103
  w.state = new Proxy({}, {
104
- set: (obj, prop, value) => {
104
+ set: async (obj, prop, value) => {
105
+ await w.ready()
105
106
  console.log('state change:', prop, value)
106
107
  if (this[prop] === value) {
107
108
  return true
@@ -121,7 +122,14 @@ w.state = new Proxy({}, {
121
122
 
122
123
  w.get = async (url, options = {}, transform, key) => {
123
124
  console.log(`fetching ${url}`)
124
- let data = await (await fetch(url, options)).json()
125
+ let data
126
+ if (url.startsWith('{') || url.startsWith('[')) {
127
+ data = JSON.parse(url)
128
+ } else {
129
+ let f = await fetch(url, options)
130
+ if (!f.ok) throw Error(`Could not fetch ${url}`)
131
+ data = await f.json()
132
+ }
125
133
  if (transform) {
126
134
  console.log('transforming ' + data)
127
135
  data = transform(data)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "enigmatic",
3
3
  "main": "enigmatic.js",
4
- "version": "0.21.2",
4
+ "version": "0.21.4",
5
5
  "scripts": {
6
6
  "test": "node test.mjs"
7
7
  },
@@ -2,3 +2,5 @@
2
2
 
3
3
  <div data="mykey" value="1"></div>
4
4
  <button onclick="state.mykey++">Increment</button>
5
+
6
+ <div data='mymessage' fetch='{"messages": "ok"}'>{messages}</div>