mithril-mobs 0.0.2 → 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.
package/README.md CHANGED
@@ -1 +1,2 @@
1
1
  # mithril-mobs
2
+ # mithril-template
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mithril-mobs",
3
3
  "private": false,
4
- "version": "0.0.2",
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) {
@@ -235,3 +229,18 @@ const Component = {
235
229
  };
236
230
 
237
231
  export const createComponent = (def) => Component.create(def);
232
+
233
+ /**
234
+ * Repeat Helper
235
+ */
236
+ export const repeat = (times, increment = 1) => {
237
+ return {
238
+ map(cb) {
239
+ const items = []
240
+ for (let i = 0; i < times; i += increment) {
241
+ items.push(cb(i));
242
+ }
243
+ return items;
244
+ }
245
+ };
246
+ };