Configuring RequireJS?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Configuring RequireJS?

rapidtransit440

I'm using UIKit in place of Bootstrap, I also needed to add a module structure, since UI Kit's dependencies look only within the base directory I tried to do this:




@Contribute(ModuleManager.class)
    public static void provideAliases(List<ModuleConfigurationCallback> callbacks){
        callbacks.add(new ModuleConfigurationCallback() {
            @Override
            public JSONObject configure(JSONObject configuration) {
                return configuration.append("paths", new JSONObject(
                        "uikit", "uikit/uikit"));
            }
        });
    }



Complains that you need use a Configuration



@Contribute(ModuleManager.class)
    public static void provideAliases(Configuration<ModuleConfigurationCallback> callbacks){
        callbacks.add(new ModuleConfigurationCallback() {
            @Override
            public JSONObject configure(JSONObject configuration) {
                return configuration.append("paths", new JSONObject(
                        "uikit", "uikit/uikit"));
            }
        });
    }


Complains you need to use a mapped configuration



@Contribute(ModuleManager.class)
    public static void provideAliases(MappedConfiguration<String, ModuleConfigurationCallback> callbacks){
        callbacks.add("paths", new ModuleConfigurationCallback() {
            @Override
            public JSONObject configure(JSONObject configuration) {
                configuration.append("paths", new JSONObject("uikit", "uikit/uikit"));
            }
        });
    }


Complains that there is no coercion to .. I forgot which class it was, and the callback is apparently a per page/component and can not be manipulated globally.


So as a last resort I just modified the JS :/, a new problem arises RequireJS is allowing my init script to run before the dependency is fully initialized. So now I really need to modify my RequireJS config. :( Anyone know how?
Reply | Threaded
Open this post in threaded view
|

Re: Configuring RequireJS?

Cezary Biernacki
Hi,
First, if you go to source code of
org.apache.tapestry5.services.javascript.ModuleManager interface, you
should see line


@UsesMappedConfiguration(JavaScriptModuleConfiguration.class)

It indicates that contributions must use MappedConfigurations with values
being JavaScriptModuleConfiguration. I recommend always checking what kind
of contributions are expected, and as far I can tell, all Tapestry built-in
services has appropriate documentation annotations. However it seems that
you want to provide ModuleConfigurationCallback, not add
JavaScriptModuleConfiguration contributions. It requires quite different
approach. In a Tapestry component or page that requires custom
configuration (e.g. I normally do this in my Layout component), inject
JavaScriptSupport service and call its addModuleConfigurationCallback()
method in one of rendering event handlers (e.g. on SetupRender), e.g.:


public class Layout {

    private static final ModuleConfigurationCallback CALLBACK = new
ModuleConfigurationCallback() {
            @Override
            public JSONObject configure(JSONObject configuration) {
                return configuration.append("paths", new
JSONObject("uikit", "uikit/uikit"));
            }
        };

    @Inject
    private JavaScriptSupport javaScriptSupport;

    @SetupRender
    public void configureRequireJS() {
        javaScriptSupport.addModuleConfigurationCallback(CALLBACK);
    }

}


Of course this component should be included on pages that require this
custom configuration, so preferably it should be one that includes your
UIKit javascript module.

Best regards,
Cezary



On Tue, Sep 13, 2016 at 4:08 PM, <[hidden email]> wrote:

>
> I'm using UIKit in place of Bootstrap, I also needed to add a module
> structure, since UI Kit's dependencies look only within the base directory
> I tried to do this:
>
>
>
>
> @Contribute(ModuleManager.class)
>     public static void provideAliases(List<ModuleConfigurationCallback>
> callbacks){
>         callbacks.add(new ModuleConfigurationCallback() {
>             @Override
>             public JSONObject configure(JSONObject configuration) {
>                 return configuration.append("paths", new JSONObject(
>                         "uikit", "uikit/uikit"));
>             }
>         });
>     }
>
>
>
> Complains that you need use a Configuration
>
>
>
> @Contribute(ModuleManager.class)
>     public static void provideAliases(Configuration<ModuleConfigurationCallback>
> callbacks){
>         callbacks.add(new ModuleConfigurationCallback() {
>             @Override
>             public JSONObject configure(JSONObject configuration) {
>                 return configuration.append("paths", new JSONObject(
>                         "uikit", "uikit/uikit"));
>             }
>         });
>     }
>
>
> Complains you need to use a mapped configuration
>
>
>
> @Contribute(ModuleManager.class)
>     public static void provideAliases(MappedConfiguration<String,
> ModuleConfigurationCallback> callbacks){
>         callbacks.add("paths", new ModuleConfigurationCallback() {
>             @Override
>             public JSONObject configure(JSONObject configuration) {
>                 configuration.append("paths", new JSONObject("uikit",
> "uikit/uikit"));
>             }
>         });
>     }
>
>
> Complains that there is no coercion to .. I forgot which class it was, and
> the callback is apparently a per page/component and can not be manipulated
> globally.
>
>
> So as a last resort I just modified the JS :/, a new problem arises
> RequireJS is allowing my init script to run before the dependency is fully
> initialized. So now I really need to modify my RequireJS config. :( Anyone
> know how?
>
Reply | Threaded
Open this post in threaded view
|

Re: Configuring RequireJS?

rapidtransit440
Ha, I was so fixated on trying to configure it through a Module I forgot about that



-----Original Message-----
From: Cezary Biernacki <[hidden email]>
To: Tapestry users <[hidden email]>
Sent: Wed, Sep 14, 2016 1:55 pm
Subject: Re: Configuring RequireJS?

Hi,
First, if you go to source code of
org.apache.tapestry5.services.javascript.ModuleManager interface, you
should see line


@UsesMappedConfiguration(JavaScriptModuleConfiguration.class)

It indicates that contributions must use MappedConfigurations with values
being JavaScriptModuleConfiguration. I recommend always checking what kind
of contributions are expected, and as far I can tell, all Tapestry built-in
services has appropriate documentation annotations. However it seems that
you want to provide ModuleConfigurationCallback, not add
JavaScriptModuleConfiguration contributions. It requires quite different
approach. In a Tapestry component or page that requires custom
configuration (e.g. I normally do this in my Layout component), inject
JavaScriptSupport service and call its addModuleConfigurationCallback()
method in one of rendering event handlers (e.g. on SetupRender), e.g.:


public class Layout {

    private static final ModuleConfigurationCallback CALLBACK = new
ModuleConfigurationCallback() {
            @Override
            public JSONObject configure(JSONObject configuration) {
                return configuration.append("paths", new
JSONObject("uikit", "uikit/uikit"));
            }
        };

    @Inject
    private JavaScriptSupport javaScriptSupport;

    @SetupRender
  public void configureRequireJS() {
        javaScriptSupport.addModuleConfigurationCallback(CALLBACK);
    }

}


Of course this component should be included on pages that require this
custom configuration, so preferably it should be one that includes your
UIKit javascript module.

Best regards,
Cezary



On Tue, Sep 13, 2016 at 4:08 PM, <[hidden email]> wrote:

>
> I'm using UIKit in place of Bootstrap, I also needed to add a module
> structure, since UI Kit's dependencies look only within the base directory
> I tried to do this:
>
>
>
>
> @Contribute(ModuleManager.class)
>     public static void provideAliases(List<ModuleConfigurationCallback>
> callbacks){
>         callbacks.add(new ModuleConfigurationCallback() {
>             @Override
>    public JSONObject configure(JSONObject configuration) {
>                 return configuration.append("paths", new JSONObject(
>                         "uikit", "uikit/uikit"));
>             }
>         });
>     }
>
>
>
> Complains that you need use a Configuration
>
>
>
> @Contribute(ModuleManager.class)
>     public static void provideAliases(Configuration<ModuleConfigurationCallback>
> callbacks){
>      callbacks.add(new ModuleConfigurationCallback() {
>             @Override
>    public JSONObject configure(JSONObject configuration) {
>                 return configuration.append("paths", new JSONObject(
>                         "uikit", "uikit/uikit"));
>             }
>         });
>     }
>
>
> Complains you need to use a mapped configuration
>
>
>
> @Contribute(ModuleManager.class)
>     public static void provideAliases(MappedConfiguration<String,
> ModuleConfigurationCallback> callbacks){
>         callbacks.add("paths", new ModuleConfigurationCallback() {
>             @Override
>             public JSONObject configure(JSONObject configuration) {
>                 configuration.append("paths", new JSONObject("uikit",
> "uikit/uikit"));
>             }
>         });
>     }
>
>
> Complains that there is no coercion to .. I forgot which class it was, and
> the callback is apparently a per page/component and can not be manipulated
> globally.
>
>
> So as a last resort I just modified the JS :/, a new problem arises
> RequireJS is allowing my init script to run before the dependency is fully
> initialized. So now I really need to modify my RequireJS config. :( Anyone
> know how?
>