CCF (Component Communication Framework)
On this page
Purpose
- CCF allows components to encapsulate their client-side code into independent requirejs modules
- Through requirejs's dependency loading, components have a clean way of defining dependencies
- Through the Event Manager interface, components can send messages to each other without tight coupling
- Allow Content Authors to configure how components use Event Manager via rendering parameters
Modules
- moduleLoader - Initializes js modules for the components on the current page
- eventManager - Used by components to send/receive event data (This is how components "talk")
- score_ccf/extensions - Contains helpful utility functions
Usage
To use Score CCF in your project, you need to...
- load Score CCF's configuration
- load your project's custom configuration
- load an "entry point" file (typically named main.js) which kicks off the module loading
Create a require.config.js file in Your.Solution.Web/Areas/YourCustomArea/js to house your project's custom configuration. The most important property to define here is the "baseUrl", which should point to your js root directory. Everything else is optional. Reference this page for all possible configuration options: http://requirejs.org/docs/api.html#config
The js files referenced in a layout file will run for all pages that use this layout. So, you can use main.js for global code (code that applies to all pages).
To create a js module for your custom component...
- Create a js file named with your component name
- In your js file, define a requirejs module, and return a function that initializes the module.
- Use Score.UI's HTML Helper to wrap your component's Razor code. This tells the Module Loader what portion of the page's HTML should be associated with what js module.
In this example, we assume that component js files are placed in Your.Solution.Web/Areas/YourCustomArea/js/Components
Minifying/Bundling js with CCF
Reference this page if you are also using javascript minification/bundling in your project: JavaScript Bundling (Alpha version)
Paths Defined in Score
Score.UI defines shortcut names for common modules and libraries. If your components depend on these modules/libraries, use the shortcut name to define dependency.
path name | description | |
---|---|---|
score_ccf | The root location of score ccf scripts | |
jqueryNoConflict | A wrapper for jquery that uses jquery's noConflict method. Behind the scenes, CCF maps all requests for "jquery" to "jqueryNoConflict" | |
jquery | jQuery JavaScript Library v2.1.4. Behind the scenes, CCF maps all requests for "jquery" to "jqueryNoConflict" | |
jqueryTouch | A jQuery plugin for unifying mouse/touch events across different browsers. Reference: http://a-fung.github.io/jQueryTouch/ | |
underscore | A js helper library. Provides 80+ functions that support both the usual functional suspects: map, filter, invoke — as well as more specialized helpers. Reference: http://underscorejs.org/ Exports the global variable "_" | |
eventManager | Score CCF's EventManager module | |
moduleLoader | Score CCF's ModuleLoader module | |
requirejs extensions | async | An extension for requirejs for resolving asynchronous dependencies. |
depend | Artem Loboda- what does this do? | |
font | Loads font files | |
goog | Loads google API files | |
image | Loads image files | |
json | Loads json files | |
mdown | Loads markdown files | |
noext | Loads files with no extension | |
propertyParser | Artem Loboda - what does this do? | |
text | Loads text files |