Skip to content

Commit

Permalink
#8 - finished migrating to vue.js ;DD
Browse files Browse the repository at this point in the history
  • Loading branch information
activey committed Oct 29, 2016
1 parent 4b22380 commit 963efc6
Show file tree
Hide file tree
Showing 38 changed files with 235 additions and 519 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static org.licket.core.view.ComponentView.fromComponentContainerClass;
import org.licket.core.module.application.LicketComponentModelReloader;
import org.licket.core.module.application.LicketRemote;
import org.licket.core.module.forms.component.AbstractLicketForm;
import org.licket.core.view.form.AbstractLicketForm;
import org.licket.core.view.form.LicketInput;
import org.licket.core.view.link.LicketFormSubmitButton;
import org.licket.demo.model.Contact;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ public VariableInitializerBuilder target(NameBuilder name) {
return this;
}

public VariableInitializerBuilder initializer(FunctionCallBuilder functionCall) {
this.initializer = functionCall;
return this;
}

public VariableInitializerBuilder initializer(KeywordLiteralBuilder keywordLiteral) {
this.initializer = keywordLiteral;
public VariableInitializerBuilder initializer(AbstractAstNodeBuilder<?> initializer) {
this.initializer = initializer;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.licket.core.id.CompositeId;
import org.licket.core.view.LicketComponent;
import org.licket.core.view.container.LicketComponentContainer;
import org.licket.core.view.hippo.angular.ngmodule.VuePlugin;
import org.licket.core.view.hippo.vue.VuePlugin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.licket.core.id.CompositeId;
import org.licket.core.view.LicketComponent;
import org.licket.core.view.container.LicketComponentContainer;
import org.licket.core.view.hippo.angular.ngmodule.VuePlugin;
import org.licket.core.view.hippo.vue.VuePlugin;

import java.util.Optional;
import java.util.function.Predicate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.licket.core.module;

import org.licket.core.module.application.ApplicationModuleConfiguration;
import org.licket.core.module.application.ApplicationModulePluginConfiguration;
import org.licket.core.module.resource.ResourcePluginConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand All @@ -11,6 +11,6 @@
@Configuration
@Import({
ResourcePluginConfiguration.class,
ApplicationModuleConfiguration.class
ApplicationModulePluginConfiguration.class
})
public class AngularModulesConfiguration {}
public class VuePluginsConfiguration {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import static java.util.Arrays.stream;
import static org.licket.framework.hippo.NameBuilder.name;
import static org.licket.framework.hippo.PropertyNameBuilder.property;
import org.licket.core.view.hippo.angular.ngmodule.VuePlugin;
import org.licket.core.view.hippo.vue.VuePlugin;
import org.licket.core.view.hippo.vue.extend.VueClass;
import org.licket.framework.hippo.PropertyNameBuilder;

import java.util.Arrays;
import java.util.function.Consumer;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package org.licket.core.module.application;

import org.licket.core.module.application.resource.ApplicationEventHubResource;
import org.licket.core.module.application.resource.ApplicationModulePluginResource;
import org.licket.core.module.resource.HttpCommunicationService;
import org.licket.core.resource.HeadParticipatingResource;
import org.licket.core.view.hippo.angular.ngmodule.VuePlugin;
import org.licket.core.view.hippo.vue.VuePlugin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

/**
* @author activey
*/
@Configuration
public class ApplicationModuleConfiguration {
public class ApplicationModulePluginConfiguration {

@Bean
public VuePlugin applicationModulePlugin(@Autowired HttpCommunicationService httpCommunicationService) {
Expand All @@ -30,6 +32,13 @@ public LicketComponentModelReloader modelReloader() {
}

@Bean
@Order(1)
public HeadParticipatingResource applicationEventHubResource() {
return new ApplicationEventHubResource();
}

@Bean
@Order(2)
public HeadParticipatingResource applicationModulePluginResource() {
return new ApplicationModulePluginResource();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,42 @@
import static org.licket.framework.hippo.ObjectLiteralBuilder.objectLiteral;
import static org.licket.framework.hippo.ObjectPropertyBuilder.propertyBuilder;
import static org.licket.framework.hippo.PropertyNameBuilder.property;
import static org.licket.framework.hippo.StringLiteralBuilder.stringLiteral;

import org.licket.core.view.hippo.vue.annotation.VueComponentFunction;
import org.licket.core.view.hippo.vue.annotation.Name;
import org.licket.core.view.hippo.vue.extend.VueClass;
import org.licket.framework.hippo.BlockBuilder;
import org.licket.framework.hippo.NameBuilder;
import org.licket.framework.hippo.NewExpressionBuilder;
import org.licket.framework.hippo.ObjectLiteralBuilder;
import org.licket.framework.hippo.PropertyNameBuilder;
import org.licket.framework.hippo.*;

/**
* @author grabslu
*/
public class LicketComponentModelReloader implements VueClass {

@Name("modelChangedEventEmitter")
private NewExpressionBuilder modelChangedEventEmitter = newExpression()
.target(property(property(name("ng"), name("core")), name("EventEmitter"))).argument(name("true"));
@Name("eventHub")
private PropertyNameBuilder eventHub = property("app", "ApplicationEventHub");

@VueComponentFunction
public void listenForModelChange(@Name("changeListener") NameBuilder changeListener, BlockBuilder body) {
body.appendStatement(expressionStatement(functionCall()
.target(property(property(thisLiteral(), name("modelChangedEventEmitter")), name("subscribe")))
.target(property(name("eventHub"), name("$on")))
.argument(modelChangedEvent())
.argument(changeListener)));
}

@VueComponentFunction
public void notifyModelChanged(@Name("compositeId") NameBuilder compositeId,
@Name("changedModelData") NameBuilder changedModelData, BlockBuilder body) {
body.appendStatement(expressionStatement(
functionCall().target(property(property(thisLiteral(), name("modelChangedEventEmitter")), name("emit")))
functionCall().target(property(name("eventHub"), name("$emit")))
.argument(modelChangedEvent())
.argument(changedModelEventData(compositeId, changedModelData))));
}

private StringLiteralBuilder modelChangedEvent() {
return stringLiteral("component-model-changed");
}

private ObjectLiteralBuilder changedModelEventData(NameBuilder compositeId, NameBuilder changedModelData) {
return objectLiteral()
.objectProperty(propertyBuilder().name("compositeId").value(compositeId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import org.licket.core.view.hippo.vue.annotation.Name;
import org.licket.core.view.hippo.vue.annotation.VueComponentFunction;
import org.licket.core.view.hippo.vue.extend.VueClass;
import org.licket.framework.hippo.BlockBuilder;
import org.licket.framework.hippo.FunctionCallBuilder;
import org.licket.framework.hippo.NameBuilder;
import org.licket.framework.hippo.*;

/**
* @author grabslu
Expand Down Expand Up @@ -51,16 +49,10 @@ public NameBuilder vueName() {
return name("$licketRemoteService");
}

public FunctionCallBuilder callSubmitForm(String formId) {
public FunctionCallBuilder callSubmitForm(String formId, PropertyNameBuilder callbackFunction) {
return functionCall()
.target(property(vueName(), name("submitForm")))
.target(property(property(thisLiteral(), vueName()), name("submitForm")))
.argument(stringLiteral(formId)).argument(property(thisLiteral(), name("model")))
.argument(functionNode().param(name("response")).body(block().appendStatement(
expressionStatement(
functionCall()
.target(property(name("vm"), name("afterSubmit")))
.argument(name("response"))
)
)));
.argument(callbackFunction);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.licket.core.module.application.resource;

import org.licket.core.resource.HeadParticipatingResource;
import org.licket.core.resource.javascript.AbstractJavascriptDynamicResource;
import org.licket.framework.hippo.*;

import static org.licket.framework.hippo.AssignmentBuilder.assignment;
import static org.licket.framework.hippo.ExpressionStatementBuilder.expressionStatement;
import static org.licket.framework.hippo.NameBuilder.name;
import static org.licket.framework.hippo.NewExpressionBuilder.newExpression;
import static org.licket.framework.hippo.PropertyNameBuilder.property;

/**
* @author activey
*/
public class ApplicationEventHubResource extends AbstractJavascriptDynamicResource implements HeadParticipatingResource {

@Override
public String getName() {
return "application-event-hub.js";
}

@Override
protected void buildJavascriptTree(BlockBuilder scriptBlockBuilder) {
scriptBlockBuilder.appendStatement(expressionStatement(
assignment()
.left(property("app", "ApplicationEventHub"))
.right(newExpression().target(name("Vue")))
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import org.licket.core.resource.HeadParticipatingResource;
import org.licket.core.resource.javascript.AbstractJavascriptDynamicResource;
import org.licket.core.view.hippo.vue.extend.VueClass;
import org.licket.core.view.hippo.vue.extend.VueExtendMethodsDecorator;
import org.licket.framework.hippo.BlockBuilder;
import org.licket.framework.hippo.FunctionNodeBuilder;
import org.licket.framework.hippo.ObjectLiteralBuilder;
import org.springframework.beans.factory.annotation.Autowired;

import static org.licket.core.view.hippo.vue.extend.VueExtendMethodsDecorator.fromClass;
import static org.licket.core.view.hippo.vue.extend.VuePropertiesDecorator.fromVueClassProperties;
import static org.licket.framework.hippo.AssignmentBuilder.assignment;
import static org.licket.framework.hippo.BlockBuilder.block;
import static org.licket.framework.hippo.ExpressionStatementBuilder.expressionStatement;
Expand Down Expand Up @@ -44,6 +44,13 @@ protected void buildJavascriptTree(BlockBuilder scriptBlockBuilder) {
.right(pluginInitializer())
)
);
scriptBlockBuilder.appendStatement(
expressionStatement(
functionCall()
.target(property("Vue", "use"))
.argument(applicationModulePlugin.vueName())
)
);
}

private FunctionNodeBuilder pluginInitializer() {
Expand All @@ -62,20 +69,19 @@ private FunctionNodeBuilder pluginInitializer() {

private ObjectLiteralBuilder services() {
ObjectLiteralBuilder services = ObjectLiteralBuilder.objectLiteral();
applicationModulePlugin.forEachService(service -> {
services.objectProperty(
propertyBuilder()
.name(service.vueName())
.value(objectLiteral().objectProperty(
propertyBuilder()
.name("get")
.value(functionNode().body(
block()
.appendStatement(
returnStatement()
.returnValue(serviceMethods(service)))))))
);
});
applicationModulePlugin.forEachService(service -> services.objectProperty(
propertyBuilder()
.name(service.vueName())
.value(objectLiteral().objectProperty(
propertyBuilder()
.name("get")
.value(functionNode()
.body(
fromVueClassProperties(service).decorate(block())
.appendStatement(
returnStatement()
.returnValue(serviceMethods(service)))))))
));
return services;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.licket.core.module.resource;

import org.licket.core.view.hippo.angular.ngclass.AngularInjectable;
import org.licket.core.view.hippo.vue.extend.VueClass;
import org.licket.framework.hippo.FunctionCallBuilder;
import org.licket.framework.hippo.NameBuilder;
import org.licket.framework.hippo.PropertyNameBuilder;

import static org.licket.framework.hippo.FunctionCallBuilder.functionCall;
import static org.licket.framework.hippo.KeywordLiteralBuilder.thisLiteral;
import static org.licket.framework.hippo.NameBuilder.name;
import static org.licket.framework.hippo.PropertyNameBuilder.property;

Expand All @@ -26,7 +24,7 @@ public FunctionCallBuilder callHttpPost(String url, NameBuilder responseListener
.target(property(functionCall()
.target(httpPostFunction())
.argument(name(url)),
subscribeHandlerFunction()))
responseCallbackFunction()))
.argument(responseListener);
}

Expand All @@ -36,16 +34,17 @@ public FunctionCallBuilder callHttpPostWithData(String url, NameBuilder data, Na
.target(httpPostFunction())
.argument(name(url))
.argument(data),
subscribeHandlerFunction()))
responseCallbackFunction()))
.argument(responseListener);
}

private PropertyNameBuilder httpPostFunction() {
return property(name("http"), name("post"));
// cant use vueName() here ;/
return property(property("Vue", "http"), name("post"));
}

private NameBuilder subscribeHandlerFunction() {
return name("subscribe");
private NameBuilder responseCallbackFunction() {
return name("then");
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.licket.core.module.resource;

import org.licket.core.module.resource.resource.ResourcePluginResource;
import org.licket.core.resource.HeadParticipatingResource;
import org.licket.core.view.hippo.angular.ngmodule.VuePlugin;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -12,11 +10,6 @@
@Configuration
public class ResourcePluginConfiguration {

@Bean
public VuePlugin resourcePlugin() {
return new ResourcePlugin();
}

@Bean
public HeadParticipatingResource resourcePluginResource() {
return new ResourcePluginResource();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.licket.core.module.resource.resource;
package org.licket.core.module.resource;

import org.licket.core.resource.HeadParticipatingResource;
import org.licket.core.resource.javascript.JavascriptStaticResource;
Expand Down
Loading

0 comments on commit 963efc6

Please sign in to comment.