A simple Durandal (AMD) VM Wrapper for the Aurelia Framework
- Open up your terminal and go into your projects root
- Type following command:
jspm install github:zewa666/durelia
- Copy a DurandalVM into your Project (e.g.
root/amd/testmodule.js
) - Create a new AureliaVM inside
src
(e.g.src/testmodule.js
) - (Optional) Create a View for your new VM (e.g.
src/testmodule.html
) - Add this code into your AureliaVM:
// Importing Durelia's wrapper
import {Wrapper} from 'durelia';
// create a local instance of your DurandalVM
let VM = new Wrapper('../amd/testmodule');
// export as function so router nows how to use your VM
export let TestModule = () => { return VM; };
You can pass a second argument to Wrapper which is the path to the View you'd like to leverage. If none is provided, following Aurelia's convention, a View with the same name as the module will be taken.
The updated version provides support for Knockout. If your Durandal VMs contain references to Knockout (take a look at the unit test stub), you have to do one additional step.
- Open the file
config.js
of your project - In the System.config.paths section add this line at the end:
"knockout": "jspm_packages/github/zewa666/durelia@master/test/knockout.js"
so it looks like:
System.config({
"paths": {
"*": "*.js",
"github:*": "jspm_packages/github/*.js",
"npm:*": "jspm_packages/npm/*.js",
...
"knockout": "jspm_packages/github/zewa666/durelia@master/test/knockout.js"
}
});
This will add a Polyfill for Knockout, which translates Observables and ObservableArray back to the original value.