clapton 0.0.14 → 0.0.15

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7def55e21b26dedfd8843c9ace0bf4db854abf18205de4dea7c3a203d06130f6
4
- data.tar.gz: 743f8549cd8a901f2f1c76a4807f05ccace77d58e9665ad35c02626df555a08a
3
+ metadata.gz: 31438028bfe58d5ce7e560543850167002e53f148784072f20834081c0421b34
4
+ data.tar.gz: 2509467d610325dbaf0c1a20a953e50ecd568b8722d1b2fd7a1bc1acbb1bd6aa
5
5
  SHA512:
6
- metadata.gz: b05ba6c72f46212b628cee66c18e01644e285e6380862669eb7de55174338b4b9109ebf69505d398227c85f0a19a6e55580e6cf760951fad573bc13d78c73845
7
- data.tar.gz: 2359db5b15a7ef59f43dc61d2bcb96609858cc0a19c996e9b18288046fe739a3d68bf5868f221c97c349af8781ff8483c979199e3c1c27914f617e8912555aba
6
+ metadata.gz: c68a61320829b1fcd198c627af8ff48de08479f1a725ebb51c14dfcbfc74277c4c0fec8735c4becf2994ebb1abcb36222a102dc9403d1d581406534a0fc11ca6
7
+ data.tar.gz: 5500b02be72eb9b161c1882ac913fd48ff6a0114e1bb3aa46b38572eb5885e00a4b2b7a10bc4968b3535331ba67916df292eb65dceff6a203e960d0c46eb47bd
@@ -21,6 +21,10 @@ module Clapton
21
21
  FileUtils.mkdir_p(components_path) unless components_path.exist?
22
22
  FileUtils.touch(components_path.join(".keep"))
23
23
 
24
+ FileUtils.mkdir_p(Rails.root.join("public", "clapton")) unless Rails.root.join("public", "clapton").exist?
25
+ File.write(Rails.root.join("public", "clapton", "components.js"), File.read(File.join(__dir__, "javascripts", "dist", "components.js")))
26
+ File.write(Rails.root.join("public", "clapton", "client.js"), File.read(File.join(__dir__, "javascripts", "dist", "client.js")))
27
+
24
28
  compile_components
25
29
 
26
30
  listener = Listen.to(Rails.root.join("app", "components")) do |modified, added, removed|
@@ -32,9 +36,9 @@ module Clapton
32
36
  end
33
37
 
34
38
  def compile_components
35
- FileUtils.mkdir_p(Rails.root.join("public", "clapton")) unless Rails.root.join("public", "clapton").exist?
36
- File.write(Rails.root.join("public", "clapton", "components.js"), File.read(File.join(__dir__, "javascripts", "dist", "components.js")))
37
- File.write(Rails.root.join("public", "clapton", "client.js"), File.read(File.join(__dir__, "javascripts", "dist", "client.js")))
39
+ puts "Clapton: Compiling components"
40
+
41
+ start_time = Time.now
38
42
  Dir.glob(Rails.root.join("app", "components", "**", "*.rb")).each do |file|
39
43
  code = File.read(file)
40
44
  js = ""
@@ -50,6 +54,8 @@ module Clapton
50
54
  js += "\n"
51
55
  File.write(Rails.root.join("public", "clapton", "#{File.basename(file, ".rb").camelize}.js"), js)
52
56
  end
57
+ end_time = Time.now
58
+ puts "Clapton: Component compilation took #{end_time - start_time} seconds"
53
59
  end
54
60
  end
55
61
  end
@@ -1287,8 +1287,7 @@ function getConfig(name) {
1287
1287
 
1288
1288
  const updateComponent = async (component, state, property, target) => {
1289
1289
  state[property] = target.value;
1290
- component.setAttribute("data-state", JSON.stringify(state));
1291
- const componentName = component.getAttribute("data-component");
1290
+ const componentName = component.dataset.component;
1292
1291
  const module = await import(`${componentName}`);
1293
1292
  const ComponentClass = module[componentName];
1294
1293
  const instance = new ComponentClass(state, component.dataset.id);
@@ -1348,26 +1347,26 @@ const handleAction = async (target, stateName, fn) => {
1348
1347
  if (!targetComponent)
1349
1348
  return;
1350
1349
  const component = target.closest(`[data-component]`);
1351
- const attribute = target.getAttribute("data-attribute");
1350
+ const attribute = target.dataset.attribute;
1352
1351
  if (attribute) {
1353
- const state = JSON.parse(component.getAttribute("data-state") || "{}");
1352
+ const state = JSON.parse(component.dataset.state || "{}");
1354
1353
  if (target.tagName === "INPUT") {
1355
1354
  state[attribute] = target.value;
1356
- component.setAttribute("data-state", JSON.stringify(state));
1355
+ component.dataset.state = JSON.stringify(state);
1357
1356
  }
1358
1357
  }
1359
1358
  claptonChannel.perform("action", {
1360
1359
  data: {
1361
1360
  component: {
1362
1361
  name: stateName.replace("State", "Component"),
1363
- id: targetComponent.getAttribute("data-id"),
1362
+ id: targetComponent.dataset.id,
1364
1363
  },
1365
1364
  state: {
1366
1365
  name: stateName,
1367
1366
  action: fn,
1368
- attributes: JSON.parse(targetComponent.getAttribute("data-state") || "{}"),
1367
+ attributes: JSON.parse(targetComponent.dataset.state || "{}"),
1369
1368
  },
1370
- params: JSON.parse(component.getAttribute("data-state") || "{}")
1369
+ params: JSON.parse(component.dataset.state || "{}")
1371
1370
  }
1372
1371
  });
1373
1372
  };
@@ -9,12 +9,12 @@ export const handleAction = async (target: HTMLElement, stateName: string, fn: s
9
9
  }
10
10
  if (!targetComponent) return;
11
11
  const component = target.closest(`[data-component]`) as HTMLElement;
12
- const attribute = target.getAttribute("data-attribute");
12
+ const attribute = target.dataset.attribute;
13
13
  if (attribute) {
14
- const state = JSON.parse(component.getAttribute("data-state") || "{}");
14
+ const state = JSON.parse(component.dataset.state || "{}");
15
15
  if (target.tagName === "INPUT") {
16
16
  state[attribute] = (target as HTMLInputElement).value;
17
- component.setAttribute("data-state", JSON.stringify(state));
17
+ component.dataset.state = JSON.stringify(state);
18
18
  }
19
19
  };
20
20
  claptonChannel.perform(
@@ -23,14 +23,14 @@ export const handleAction = async (target: HTMLElement, stateName: string, fn: s
23
23
  data: {
24
24
  component: {
25
25
  name: stateName.replace("State", "Component"),
26
- id: targetComponent.getAttribute("data-id"),
26
+ id: targetComponent.dataset.id,
27
27
  },
28
28
  state: {
29
29
  name: stateName,
30
30
  action: fn,
31
- attributes: JSON.parse(targetComponent.getAttribute("data-state") || "{}"),
31
+ attributes: JSON.parse(targetComponent.dataset.state || "{}"),
32
32
  },
33
- params: JSON.parse(component.getAttribute("data-state") || "{}")
33
+ params: JSON.parse(component.dataset.state || "{}")
34
34
  }
35
35
  }
36
36
  );
@@ -2,8 +2,7 @@ import morphdom from "morphdom";
2
2
 
3
3
  export const updateComponent = async (component: HTMLElement, state: any, property: string, target: HTMLInputElement) => {
4
4
  state[property] = target.value;
5
- component.setAttribute("data-state", JSON.stringify(state));
6
- const componentName = component.getAttribute("data-component") as string;
5
+ const componentName = component.dataset.component as string;
7
6
  const module = await import(`${componentName}`);
8
7
  const ComponentClass = module[componentName] as any;
9
8
  const instance = new ComponentClass(state, component.dataset.id);
@@ -1,4 +1,3 @@
1
1
  module Clapton
2
- VERSION = '0.0.14'
2
+ VERSION = '0.0.15'
3
3
  end
4
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clapton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moeki Kawakami