mithril-mobs 0.0.3 → 0.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/mobs/index.js +12 -21
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mithril-mobs",
3
3
  "private": false,
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
package/src/mobs/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import m from "mithril"
1
+ import m from "mithril";
2
2
 
3
3
  /**
4
4
  * Reactive Observable (obs)
@@ -171,7 +171,7 @@ function prepare(ctx) {
171
171
  }
172
172
 
173
173
  /**
174
- * Styled Component Creator
174
+ * Styled Component Creator - MULTIPLE <style> TAG VERSION
175
175
  */
176
176
  const Component = {
177
177
  _counter: 0,
@@ -199,20 +199,14 @@ const Component = {
199
199
  return css;
200
200
  }
201
201
 
202
- let styleTag = document.getElementById("component-styles");
203
- if (!styleTag) {
204
- styleTag = document.createElement("style");
205
- styleTag.id = "component-styles";
202
+ // Inject a new <style> tag per component
203
+ if (def.staticStyles) {
204
+ const styleTag = document.createElement("style");
205
+ styleTag.setAttribute("data-comp-id", compId);
206
+ styleTag.textContent = stylesToCss(def.staticStyles);
206
207
  document.head.appendChild(styleTag);
207
208
  }
208
209
 
209
- styleTag.__injectedComponents = styleTag.__injectedComponents || new Set();
210
-
211
- if (!styleTag.__injectedComponents.has(compId)) {
212
- styleTag.appendChild(document.createTextNode(stylesToCss(def.staticStyles || {})));
213
- styleTag.__injectedComponents.add(compId);
214
- }
215
-
216
210
  return {
217
211
  ...def,
218
212
  view(vnode) {
@@ -236,9 +230,6 @@ const Component = {
236
230
 
237
231
  export const createComponent = (def) => Component.create(def);
238
232
 
239
-
240
-
241
-
242
233
  /**
243
234
  * Repeat Helper
244
235
  */
@@ -246,10 +237,10 @@ export const repeat = (times, increment = 1) => {
246
237
  return {
247
238
  map(cb) {
248
239
  const items = []
249
- for(let i = 0; i < times; i+=increment) {
250
- items.push(cb(i))
240
+ for (let i = 0; i < times; i += increment) {
241
+ items.push(cb(i));
251
242
  }
252
- return items
243
+ return items;
253
244
  }
254
- }
255
- }
245
+ };
246
+ };