clapton 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31438028bfe58d5ce7e560543850167002e53f148784072f20834081c0421b34
|
4
|
+
data.tar.gz: 2509467d610325dbaf0c1a20a953e50ecd568b8722d1b2fd7a1bc1acbb1bd6aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c68a61320829b1fcd198c627af8ff48de08479f1a725ebb51c14dfcbfc74277c4c0fec8735c4becf2994ebb1abcb36222a102dc9403d1d581406534a0fc11ca6
|
7
|
+
data.tar.gz: 5500b02be72eb9b161c1882ac913fd48ff6a0114e1bb3aa46b38572eb5885e00a4b2b7a10bc4968b3535331ba67916df292eb65dceff6a203e960d0c46eb47bd
|
data/lib/clapton/engine.rb
CHANGED
@@ -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
|
-
|
36
|
-
|
37
|
-
|
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.
|
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.
|
1350
|
+
const attribute = target.dataset.attribute;
|
1352
1351
|
if (attribute) {
|
1353
|
-
const state = JSON.parse(component.
|
1352
|
+
const state = JSON.parse(component.dataset.state || "{}");
|
1354
1353
|
if (target.tagName === "INPUT") {
|
1355
1354
|
state[attribute] = target.value;
|
1356
|
-
component.
|
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.
|
1362
|
+
id: targetComponent.dataset.id,
|
1364
1363
|
},
|
1365
1364
|
state: {
|
1366
1365
|
name: stateName,
|
1367
1366
|
action: fn,
|
1368
|
-
attributes: JSON.parse(targetComponent.
|
1367
|
+
attributes: JSON.parse(targetComponent.dataset.state || "{}"),
|
1369
1368
|
},
|
1370
|
-
params: JSON.parse(component.
|
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.
|
12
|
+
const attribute = target.dataset.attribute;
|
13
13
|
if (attribute) {
|
14
|
-
const state = JSON.parse(component.
|
14
|
+
const state = JSON.parse(component.dataset.state || "{}");
|
15
15
|
if (target.tagName === "INPUT") {
|
16
16
|
state[attribute] = (target as HTMLInputElement).value;
|
17
|
-
component.
|
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.
|
26
|
+
id: targetComponent.dataset.id,
|
27
27
|
},
|
28
28
|
state: {
|
29
29
|
name: stateName,
|
30
30
|
action: fn,
|
31
|
-
attributes: JSON.parse(targetComponent.
|
31
|
+
attributes: JSON.parse(targetComponent.dataset.state || "{}"),
|
32
32
|
},
|
33
|
-
params: JSON.parse(component.
|
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.
|
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);
|
data/lib/clapton/version.rb
CHANGED