Skip to content

Commit 6c98605

Browse files
committed
Add JavascriptResource
1 parent 4514f7d commit 6c98605

File tree

4 files changed

+234
-56
lines changed

4 files changed

+234
-56
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
<groupId>io.github.jeemv.springboot.vuejs</groupId>
88
<artifactId>springboot-vuejs</artifactId>
9-
<version>1.0.12</version>
9+
<version>1.0.13</version>
1010

1111
<name>springboot-vuejs</name>
1212
<url>https://github.com/jeeMv/SpringBoot-VueJS</url>
13-
<description>a java wrapper for VueJS in SpringBoot.</description>
13+
<description>a java wrapper for VueJS in Spring-boot.</description>
1414

1515
<developers>
1616
<developer>

src/main/java/io/github/jeemv/springboot/vuejs/AbstractVueJS.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,15 @@ public void onUpdated(String body) {
295295
addHook("updated", body);
296296
}
297297

298+
/**
299+
* Adds code (body) for the updated hook
300+
* wait until the entire view has been re-rendered with $nextTick
301+
* @param body the code to execute
302+
*/
303+
public void onUpdatedNextTick(String body) {
304+
addHook("updated", "this.$nextTick(function () {"+body+"})");
305+
}
306+
298307
/**
299308
* Adds code (body) for the beforeDestroy hook
300309
* @param body the code to execute

src/main/java/io/github/jeemv/springboot/vuejs/VueJS.java

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,131 +21,135 @@
2121
import io.github.jeemv.springboot.vuejs.parts.VueFilter;
2222
import io.github.jeemv.springboot.vuejs.utilities.JsUtils;
2323

24-
2524
/**
26-
* VueJS instance
27-
* This class is part of springBoot-VueJS
25+
* VueJS instance This class is part of springBoot-VueJS
26+
*
2827
* @author jcheron myaddressmail@gmail.com
2928
* @version 1.0.3
3029
*
3130
*/
3231
@Component
33-
public class VueJS extends AbstractVueJS{
32+
public class VueJS extends AbstractVueJS {
3433
protected String el;
3534
protected String[] delimiters;
3635
protected boolean useAxios;
3736
protected boolean vuetify;
38-
protected Map<String,VueComponent> globalComponents;
39-
protected Map<String,AbstractVueComposition> globalElements;
40-
37+
protected Map<String, VueComponent> globalComponents;
38+
protected Map<String, AbstractVueComposition> globalElements;
39+
4140
@Autowired(required = false)
4241
protected VueJSAutoConfiguration vueJSAutoConfiguration;
4342
private Logger logger;
44-
43+
4544
@PostConstruct
46-
public void init() {
47-
if (null == vueJSAutoConfiguration) {
48-
logger.debug("VueJS configuration not yet loaded");
49-
} else {
50-
VueJSProperties vueJSProperties=vueJSAutoConfiguration.getVueJSProperties();
51-
setDelimiters(vueJSProperties.getPrefix(), vueJSProperties.getPostfix());
52-
if(vueJSProperties.isUseAxios()) {
53-
useAxios=true;
54-
}
55-
if(vueJSProperties.isVuetify()) {
56-
vuetify=true;
57-
}
58-
el=vueJSProperties.getEl();
59-
}
60-
}
61-
45+
public void init() {
46+
if (null == vueJSAutoConfiguration) {
47+
logger.debug("VueJS configuration not yet loaded");
48+
} else {
49+
VueJSProperties vueJSProperties = vueJSAutoConfiguration.getVueJSProperties();
50+
setDelimiters(vueJSProperties.getPrefix(), vueJSProperties.getPostfix());
51+
if (vueJSProperties.isUseAxios()) {
52+
useAxios = true;
53+
}
54+
if (vueJSProperties.isVuetify()) {
55+
vuetify = true;
56+
}
57+
el = vueJSProperties.getEl();
58+
}
59+
}
60+
6261
/**
6362
* @param element the DOM selector for the VueJS application
6463
*/
6564
public VueJS(String element) {
6665
super();
67-
this.el=element;
68-
globalComponents=new HashMap<>();
69-
globalElements=new HashMap<>();
66+
this.el = element;
67+
globalComponents = new HashMap<>();
68+
globalElements = new HashMap<>();
7069
logger = LoggerFactory.getLogger(VueJS.class);
7170
}
72-
71+
7372
/**
7473
* Starts the VueJS app with v-app element
7574
*/
7675
public VueJS() {
7776
this("v-app");
7877
}
79-
78+
8079
/**
8180
* Defines the element delimiters (&lt;% %&gt;)
81+
*
8282
* @param start default: &lt;%
83-
* @param end default: %&gt;
83+
* @param end default: %&gt;
8484
*/
85-
public void setDelimiters(String start,String end) {
86-
delimiters= new String[] {start,end};
85+
public void setDelimiters(String start, String end) {
86+
delimiters = new String[] { start, end };
8787
}
88-
88+
8989
/**
9090
* Returns the generated script creating the VueJS instance
91+
*
9192
* @return the generated script (javascript)
9293
*/
9394
@Override
9495
public String getScript() {
95-
String script="";
96-
if(useAxios) {
97-
script="Vue.prototype.$http = axios;\n";
96+
String script = "";
97+
if (useAxios) {
98+
script = "Vue.prototype.$http = axios;\n";
9899
}
99100
try {
100-
for(Entry<String, VueComponent> entry:globalComponents.entrySet()) {
101-
script+=entry.getValue();
101+
for (Entry<String, VueComponent> entry : globalComponents.entrySet()) {
102+
script += entry.getValue();
102103
}
103-
for(Entry<String, AbstractVueComposition> entry:globalElements.entrySet()) {
104-
script+=entry.getValue().getScript();
104+
for (Entry<String, AbstractVueComposition> entry : globalElements.entrySet()) {
105+
script += entry.getValue().getScript();
105106
}
106-
script+="new Vue("+JsUtils.objectToJSON(this)+");";
107-
return "<script>"+script+"</script>";
107+
script += "new Vue(" + JsUtils.objectToJSON(this) + ");";
108+
return "<script>" + script + "</script>";
108109
} catch (JsonProcessingException e) {
109110
e.printStackTrace();
110111
}
111112
return script;
112113
}
113-
114+
114115
/**
115116
* Adds a new global component
117+
*
116118
* @param name The component name
117119
* @return The created component
118120
*/
119121
public VueComponent addGlobalComponent(String name) {
120-
VueComponent component= new VueComponent(name);
121-
globalComponents.put(name,component);
122+
VueComponent component = new VueComponent(name);
123+
globalComponents.put(name, component);
122124
return component;
123125
}
124-
126+
125127
/**
126128
* Adds a new global directive
129+
*
127130
* @param name The directive name
128131
* @return The created directive
129132
*/
130133
public VueDirective addGlobalDirective(String name) {
131-
VueDirective directive=new VueDirective(name);
134+
VueDirective directive = new VueDirective(name);
132135
globalElements.put(name, directive);
133136
return directive;
134137
}
135-
138+
136139
/**
137140
* Adds a new global filter
141+
*
138142
* @param name The filter name
139143
* @param body The filter body
140144
* @param args The filter arguments
141145
* @return The created filter
142146
*/
143-
public VueFilter addGlobalFilter(String name,String body,String...args) {
144-
VueFilter filter=new VueFilter(name,body,args);
147+
public VueFilter addGlobalFilter(String name, String body, String... args) {
148+
VueFilter filter = new VueFilter(name, body, args);
145149
globalElements.put(name, filter);
146150
return filter;
147151
}
148-
152+
149153
public String getEl() {
150154
return el;
151155
}
@@ -154,14 +158,15 @@ public String[] getDelimiters() {
154158
return delimiters;
155159
}
156160

157-
158161
public void setEl(String el) {
159162
this.el = el;
160163
}
161164

162165
/**
163-
* Sets axios as library to use for $http
164-
* do not forget to include the corresponding js file
166+
* Sets axios as library to use for $http do not forget to include the
167+
* corresponding js file
168+
*
169+
* @param useAxios
165170
*/
166171
public void setUseAxios(boolean useAxios) {
167172
this.useAxios = useAxios;

0 commit comments

Comments
 (0)