-
-
Save niieani/bd1ee888a9311027156b29b7df6ac27e to your computer and use it in GitHub Desktop.
Aurelia RequireJS Gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<!-- Simple usage: --> | |
<h1>message: ${async(message).value}</h1> | |
<!-- With a placeholder: --> | |
<h1>message: ${async(message).value ? async(message).value : '...'}</h1> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {asyncBindings} from './enhance-promise'; | |
@asyncBindings | |
export class App { | |
message = new Promise((resolve) => setTimeout(() => resolve('Hello World!'), 2000)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function enhancePromiseForAureliaBinding(promise) { | |
if (!promise || typeof promise.then != 'function') return; | |
if (promise.hasOwnProperty('value')) return promise; | |
const observableGetter = function() { | |
return; // this is the default value of the unresolved promise | |
} | |
observableGetter.getObserver = function(promise) { | |
return { | |
subscribe: function(context, binding) { | |
promise.then(value => binding.updateTarget(value)); | |
} | |
} | |
} | |
Object.defineProperty(promise, 'value', { | |
get: observableGetter, | |
enumerable: true, | |
configurable: true | |
}) | |
return promise; | |
} | |
export function asyncBindings(definition) { | |
if (definition) { | |
definition.prototype.async = enhancePromiseForAureliaBinding; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Aurelia</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script> | |
<script> | |
require(['aurelia-bootstrapper']); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment