Skip to content

Commit e9e5b2c

Browse files
committed
adjusted vue implementation following vue 3 migration guide, refactored vue implementation on the way, removed vuex and v-runtime-template dependency, started Matestack 3 migration guide
1 parent e5a3bc2 commit e9e5b2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+3036
-2720
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ gemspec
1414
group :development, :test do
1515
gem 'rspec-rails', '~> 4.0.2'
1616
gem 'capybara'
17-
gem 'webpacker', '~> 4.0'
17+
gem 'webpacker', '~> 5.0'
1818
gem 'pg', '>= 0.18', '< 2.0'
1919
gem 'selenium-webdriver'
2020
gem 'puma'

Gemfile.lock

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
matestack-ui-core (2.1.0)
4+
matestack-ui-core (2.1.1)
55
rails (>= 5.2)
66

77
GEM
@@ -80,7 +80,7 @@ GEM
8080
xpath (~> 3.2)
8181
childprocess (3.0.0)
8282
coderay (1.1.3)
83-
concurrent-ruby (1.1.8)
83+
concurrent-ruby (1.1.9)
8484
crack (0.4.5)
8585
rexml
8686
crass (1.0.6)
@@ -93,19 +93,21 @@ GEM
9393
globalid (0.4.2)
9494
activesupport (>= 4.2.0)
9595
hashdiff (1.0.1)
96-
i18n (1.8.10)
96+
i18n (1.8.11)
9797
concurrent-ruby (~> 1.0)
98-
loofah (2.9.1)
98+
loofah (2.13.0)
9999
crass (~> 1.0.2)
100100
nokogiri (>= 1.5.9)
101101
mail (2.7.1)
102102
mini_mime (>= 0.1.1)
103103
marcel (1.0.1)
104104
method_source (1.0.0)
105105
mini_mime (1.0.3)
106-
minitest (5.14.4)
106+
mini_portile2 (2.7.1)
107+
minitest (5.15.0)
107108
nio4r (2.5.7)
108-
nokogiri (1.11.4-x86_64-linux)
109+
nokogiri (1.13.0)
110+
mini_portile2 (~> 2.7.0)
109111
racc (~> 1.4)
110112
pg (1.2.3)
111113
pry (0.13.1)
@@ -119,9 +121,9 @@ GEM
119121
public_suffix (4.0.6)
120122
puma (5.3.1)
121123
nio4r (~> 2.0)
122-
racc (1.5.2)
124+
racc (1.6.0)
123125
rack (2.2.3)
124-
rack-proxy (0.6.5)
126+
rack-proxy (0.7.2)
125127
rack
126128
rack-test (1.1.0)
127129
rack (>= 1.0, < 3)
@@ -143,15 +145,15 @@ GEM
143145
rails-dom-testing (2.0.3)
144146
activesupport (>= 4.2.0)
145147
nokogiri (>= 1.6)
146-
rails-html-sanitizer (1.3.0)
148+
rails-html-sanitizer (1.4.2)
147149
loofah (~> 2.3)
148150
railties (6.1.3.2)
149151
actionpack (= 6.1.3.2)
150152
activesupport (= 6.1.3.2)
151153
method_source
152154
rake (>= 0.8.7)
153155
thor (~> 1.0)
154-
rake (13.0.3)
156+
rake (13.0.6)
155157
regexp_parser (2.1.1)
156158
rexml (3.2.5)
157159
rspec-core (3.10.1)
@@ -175,6 +177,7 @@ GEM
175177
selenium-webdriver (3.142.7)
176178
childprocess (>= 0.5, < 4.0)
177179
rubyzip (>= 1.2.2)
180+
semantic_range (3.0.0)
178181
simplecov (0.21.2)
179182
docile (~> 1.1)
180183
simplecov-html (~> 0.11)
@@ -188,23 +191,24 @@ GEM
188191
actionpack (>= 4.0)
189192
activesupport (>= 4.0)
190193
sprockets (>= 3.0.0)
191-
thor (1.1.0)
194+
thor (1.2.1)
192195
tzinfo (2.0.4)
193196
concurrent-ruby (~> 1.0)
194197
webmock (3.13.0)
195198
addressable (>= 2.3.6)
196199
crack (>= 0.3.2)
197200
hashdiff (>= 0.4.0, < 2.0.0)
198-
webpacker (4.3.0)
199-
activesupport (>= 4.2)
201+
webpacker (5.4.3)
202+
activesupport (>= 5.2)
200203
rack-proxy (>= 0.6.1)
201-
railties (>= 4.2)
204+
railties (>= 5.2)
205+
semantic_range (>= 2.3.0)
202206
websocket-driver (0.7.3)
203207
websocket-extensions (>= 0.1.0)
204208
websocket-extensions (0.1.5)
205209
xpath (3.2.0)
206210
nokogiri (~> 1.8)
207-
zeitwerk (2.4.2)
211+
zeitwerk (2.5.3)
208212

209213
PLATFORMS
210214
ruby
@@ -222,7 +226,7 @@ DEPENDENCIES
222226
selenium-webdriver
223227
simplecov
224228
webmock
225-
webpacker (~> 4.0)
229+
webpacker (~> 5.0)
226230

227231
BUNDLED WITH
228232
2.1.4

V3_MIGRATION.md

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
# Installation & setup changes
2+
3+
## IE 11 support dropped
4+
5+
- vue3 dropped IE 11 support
6+
- when using babel alongside webpacker, please adjust your package.json or .browserslistrc config in order to exclude IE 11 support:
7+
8+
```json
9+
{
10+
"name": "my app",
11+
"...": { },
12+
"browserslist": [
13+
"defaults",
14+
"not IE 11" // <-- important!
15+
]
16+
}
17+
```
18+
19+
Otherwise you may encounter issues around `regeneratorRuntime`
20+
21+
## Setup via webpacker
22+
23+
`config/webpack/environment.js`
24+
```js
25+
const { environment } = require('@rails/webpacker')
26+
const webpack = require('webpack');
27+
28+
const customWebpackConfig = {
29+
resolve: {
30+
alias: {
31+
vue: 'vue/dist/vue.esm-bundler',
32+
}
33+
},
34+
plugins: [
35+
new webpack.DefinePlugin({
36+
__VUE_OPTIONS_API__: true,
37+
__VUE_PROD_DEVTOOLS__: false
38+
})
39+
]
40+
}
41+
42+
environment.config.merge(customWebpackConfig)
43+
44+
module.exports = environment
45+
```
46+
47+
and then just use `import { whatever } from 'vue'` instead of `import { whatever } from 'vue/dist/vue.esm'`
48+
49+
**Optional: vue3 compat build usage**
50+
51+
- if you're using any vue2 APIs (or one of the libraries you're using), you can use the vue3 compat build
52+
- this enables you to use both vue2 and vue3 APIs and migrate step by step
53+
- usage via webpack config when using webpacker 5.x and up:
54+
55+
`config/webpack/environment.js`
56+
```js
57+
const { environment } = require('@rails/webpacker')
58+
const webpack = require('webpack')
59+
60+
const customWebpackConfig = {
61+
resolve: {
62+
alias: {
63+
vue: '@vue/compat/dist/vue.esm-bundler',
64+
}
65+
},
66+
plugins: [
67+
new webpack.DefinePlugin({
68+
__VUE_OPTIONS_API__: true,
69+
__VUE_PROD_DEVTOOLS__: false
70+
})
71+
]
72+
}
73+
74+
environment.config.merge(customWebpackConfig)
75+
76+
module.exports = environment
77+
```
78+
79+
# vue.js changes
80+
81+
## app definition and mount
82+
83+
`javascript/packs/application.js`
84+
```js
85+
import { createApp } from 'vue'
86+
import MatestackUiCore from 'matestack-ui-core'
87+
88+
const appInstance = createApp({})
89+
90+
document.addEventListener('DOMContentLoaded', () => {
91+
MatestackUiCore.mount(appInstance, '#matestack-ui') // use this mount method
92+
})
93+
```
94+
95+
## custom component registration
96+
97+
`some/component/file.js`
98+
```js
99+
import MatestackUiCore from 'matestack-ui-core'
100+
101+
const myComponent = {
102+
mixins: [MatestackUiCore.componentMixin],
103+
template: MatestackUiCore.componentHelpers.inlineTemplate,
104+
data() {
105+
return {
106+
foo: "bar"
107+
};
108+
},
109+
mounted(){
110+
console.log("custom component mounted")
111+
}
112+
};
113+
114+
export default myComponent
115+
```
116+
117+
`javascript/packs/application.js`
118+
```js
119+
import { createApp } from 'vue'
120+
import MatestackUiCore from 'matestack-ui-core'
121+
122+
import myComponent from 'some/component/file.js' // import component definition from source
123+
124+
const appInstance = createApp({})
125+
126+
appInstance.component('my-component', myComponent) // register at appInstance
127+
128+
document.addEventListener('DOMContentLoaded', () => {
129+
MatestackUiCore.mount(appInstance, '#matestack-ui')
130+
})
131+
```
132+
133+
## component template
134+
135+
- For application components, apply `template: MatestackUiCore.componentHelpers.inlineTemplate`
136+
137+
`some/component/file.js`
138+
```js
139+
import MatestackUiCore from 'matestack-ui-core'
140+
141+
const myComponent = {
142+
mixins: [MatestackUiCore.componentMixin],
143+
template: MatestackUiCore.componentHelpers.inlineTemplate, // this one!
144+
data() {
145+
return {
146+
foo: "bar"
147+
};
148+
},
149+
mounted(){
150+
console.log("custom component mounted")
151+
}
152+
};
153+
154+
export default myComponent
155+
```
156+
157+
- Only for core components
158+
- add import `import componentHelpers from 'some/relative/path/to/helpers'`
159+
- and then apply `template: componentHelpers.inlineTemplate`
160+
161+
## component scope prefix
162+
163+
- use `vc.` or `vueComponent.` in order to prefix all properties references or method calls within your vue.js component `response`
164+
165+
`some/component/file.js`
166+
```js
167+
import MatestackUiCore from 'matestack-ui-core'
168+
169+
const myComponent = {
170+
mixins: [MatestackUiCore.componentMixin],
171+
template: MatestackUiCore.componentHelpers.inlineTemplate,
172+
data() {
173+
return {
174+
foo: "bar"
175+
};
176+
},
177+
mounted(){
178+
console.log(this.foo) // --> bar
179+
// or:
180+
console.log(vc.foo) // --> bar
181+
}
182+
};
183+
184+
export default myComponent
185+
```
186+
187+
```ruby
188+
class Components::MyComponent < Matestack::Ui::VueJsComponent
189+
vue_name "my-component"
190+
191+
def response
192+
div do
193+
plain "{{foo}}" # --> undefined!
194+
plain "{{vc.foo}}" # --> bar
195+
end
196+
end
197+
end
198+
```
199+
200+
## component $refs
201+
202+
- use `this.getRefs()` instead of `this.$refs`
203+
204+
## component $el
205+
206+
- use `this.getElement()` instead of `this.$el`
207+
208+
## component beforeDestroy hook
209+
210+
- `beforeDestroy` was renamed to `beforeUnmount` within vue3
211+
- Search&Replace if your're using this hook in any of your vue components
212+
213+
## $set, Vue.set
214+
215+
- `this.$set` and `Vue.set` are removed in vue3 as they are not longer required for proper reactivity binding
216+
- If you use these methods, use plain JavaScript mutations instead
217+
218+
# ruby changes
219+
220+
## matestack wrapper method
221+
222+
- removed, app wrapping is done within the app class directly now

lib/matestack/ui/core.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module VueJs
4444
require "#{vue_js_base_path}/components/form/context"
4545
require "#{vue_js_base_path}/components/form/base"
4646
require "#{vue_js_base_path}/components/form/form"
47+
require "#{vue_js_base_path}/components/form/nested_form"
4748
require "#{vue_js_base_path}/components/form/input"
4849
require "#{vue_js_base_path}/components/form/textarea"
4950
require "#{vue_js_base_path}/components/form/checkbox"

0 commit comments

Comments
 (0)