opal-vite 0.2.14 → 0.2.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: 93399be68e49a18a612682b0fe50eb3791fda0a6dc14ddbcd8f9970e5d29be7b
4
- data.tar.gz: 4153c1d7194c000104493d2be30516e5db36b9231e947b0aa6f72ce4f3930fef
3
+ metadata.gz: 022e137267f9f6c1dde7aafeea3d56658e572d7a568d3cad25e7e3e4ea93edc6
4
+ data.tar.gz: 9a2aa4af5c09bee93073f84b2afa9ca78f332fd8858ce6ddfd21f5d96928b412
5
5
  SHA512:
6
- metadata.gz: e184450fa18a680b8155b2c3190781ef31de310eae209659a493fe601ed25421981b0c777ef44f631daef7c16a50a6065ba8fb6d6c850fa2bc7f4478c5ecf56c
7
- data.tar.gz: 8dd3d802b5e6f476dec0b402de184b55f55a5fc111af0fe1ca804072205d1108e80a30114ef70f534a8033e3da34faf4b280e4d2a86d5f42fd1e300ec1fccfc7
6
+ metadata.gz: 27f1206bfd58eda0c91e7f7031181eb05d3595e9ef675d8901a403d69e7b87fae4c6dd9a85daf187b7985db058ef619d546865cee303483140d6eb5c20d8b640
7
+ data.tar.gz: 22803cc1346dd41898a1ad30fd35697ca634045209665295f553ec7608081b16c96f45b1fe7a7a23e37049407777d376f7d3c5ad5eed29e1daa742cc50126361
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Vite
3
- VERSION = "0.2.14"
3
+ VERSION = "0.2.15"
4
4
  end
5
5
  end
@@ -85,6 +85,86 @@ module OpalVite
85
85
  result.to_n
86
86
  end
87
87
 
88
+ # ===================
89
+ # Vue Function Helpers
90
+ # ===================
91
+
92
+ # Wrap any Ruby proc/lambda in a pure JS function (removes $$class property)
93
+ # Use this for Vue options that expect functions (data, lifecycle hooks, etc.)
94
+ # @param block [Proc] Any Ruby proc or lambda
95
+ # @return [Function] Pure JS function for Vue compatibility
96
+ #
97
+ # Usage:
98
+ # data: vue_fn { { count: 0 }.to_n }
99
+ # someCallback: vue_fn { |arg| process(arg) }
100
+ def vue_fn(&block)
101
+ `(function() { var fn = #{block}; return function() { return fn.apply(this, arguments); }; })()`
102
+ end
103
+
104
+ # ===================
105
+ # Vue Method/Computed Helpers (解決策②)
106
+ # ===================
107
+ # These helpers reduce backtick JavaScript by wrapping Vue's `this`
108
+ # in a Native object, allowing Ruby-style property access.
109
+ #
110
+ # Example:
111
+ # methods: {
112
+ # increment: vue_method { |vm| vm[:count] += 1 }
113
+ # }
114
+ #
115
+ # Instead of:
116
+ # methods: `{ increment() { this.count++ } }`
117
+
118
+ # Create a Vue method that receives `this` as Native-wrapped vm
119
+ # @param block [Proc] Block that receives vm (Native-wrapped this) and optional arguments
120
+ # @return [Function] Pure JS function (no $$class property) for Vue compatibility
121
+ #
122
+ # Usage:
123
+ # increment: vue_method { |vm| vm[:count] += 1 }
124
+ # greet: vue_method { |vm, name| console_log("Hello, #{name}!") }
125
+ # remove: vue_method { |vm, id| service.remove(id) }
126
+ #
127
+ # Note: When Vue calls the method, `this` is captured and passed as the first argument.
128
+ # Additional arguments from Vue (e.g., @click="removeTodo(todo.id)") are also passed.
129
+ def vue_method(&block)
130
+ p = proc do |*args|
131
+ vm = Native(`this`)
132
+ block.call(vm, *args)
133
+ end
134
+ # Wrap in pure JS function to avoid Vue $$class warning
135
+ `(function() { var fn = #{p}; return function() { return fn.apply(this, arguments); }; })()`
136
+ end
137
+
138
+ # Create a Vue computed getter that receives `this` as Native-wrapped vm
139
+ # @param block [Proc] Block that receives vm and returns computed value
140
+ # @return [Function] Pure JS function (no $$class property) for Vue compatibility
141
+ #
142
+ # Usage:
143
+ # doubled: vue_computed_fn { |vm| vm[:count] * 2 }
144
+ def vue_computed_fn(&block)
145
+ p = proc do
146
+ vm = Native(`this`)
147
+ block.call(vm)
148
+ end
149
+ # Wrap in pure JS function to avoid Vue $$class warning
150
+ `(function() { var fn = #{p}; return function() { return fn.apply(this, arguments); }; })()`
151
+ end
152
+
153
+ # Create a Vue lifecycle hook that receives `this` as Native-wrapped vm
154
+ # @param block [Proc] Block that receives vm
155
+ # @return [Function] Pure JS function (no $$class property) for Vue compatibility
156
+ #
157
+ # Usage:
158
+ # mounted: vue_hook { |vm| console_log("Mounted with count: #{vm[:count]}") }
159
+ def vue_hook(&block)
160
+ p = proc do
161
+ vm = Native(`this`)
162
+ block.call(vm)
163
+ end
164
+ # Wrap in pure JS function to avoid Vue $$class warning
165
+ `(function() { var fn = #{p}; return function() { return fn.apply(this, arguments); }; })()`
166
+ end
167
+
88
168
  # ===================
89
169
  # Lifecycle Hooks
90
170
  # ===================
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-vite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - stofu1234