Skip to content

Instantly share code, notes, and snippets.

@zo0m
Created April 2, 2020 12:44
Show Gist options
  • Save zo0m/0f3eb18f811e56dab277a5a7d69e8f8d to your computer and use it in GitHub Desktop.
Save zo0m/0f3eb18f811e56dab277a5a7d69e8f8d to your computer and use it in GitHub Desktop.
Alloy bind_ attribute
var sourceMapper = require('./sourceMapper');
var paths = require('global-paths');
var projectDirectory;
var logger;
function resolver(moduleName) {
return require(require('resolve').sync(moduleName, {
basedir: projectDirectory,
paths: paths(),
}));
}
task('pre:load', (event, alloyLogger) => {
logger = alloyLogger;
projectDirectory = event.dir.project;
sourceMapper.OPTIONS_OUTPUT.presets = sourceMapper.OPTIONS_OUTPUT.presets || [];
sourceMapper.OPTIONS_OUTPUT.presets.push(resolver('babel-preset-env'));
sourceMapper.OPTIONS_OUTPUT.presets.push({
plugins: [
[resolver('babel-plugin-titanium-controller-args')],
[bind_AttributeTransformer],
[resolver('babel-plugin-transform-async-generator-functions')]
],
});
});
function bind_AttributeTransformer(_ref) {
var types = _ref.types;
return {
pre: function (state) {
},
visitor: {
Property: function (path, state) {
if (types.isStringLiteral(path.node.value)) {
// if (path.node.value.value.startsWith('@:')) {
var namePrefix = 'bind_';
if (path.node.key.name && path.node.key.name.startsWith(namePrefix)) {
path.replaceWith(types.ObjectProperty(types.identifier(path.node.key.name), types.Identifier(path.node.value.value)));
path.node.key.name = path.node.key.name.slice(namePrefix.length);
}
}
},
}
};
};
Alloy
Require(src='components/common/base-window/BaseWindow')
Require#loader(src="components/common/horizontal-scroller/LoadingContainer")
Require#eventMap(src="components/event/map/EventMap", bind_onLoad="(()=> $.loader.onload())")
Alloy
Require(src='components/common/base-window/BaseWindow')
Require#scroller(
src="components/common/horizontal-scroller/HorizontalScroller",
module="app/ui/components",
bind_startIndex="getCurrentListIndex($.args.event)",
bind_createNextView="createNextView",
bind_createPrevView="createPrevView",
bind_handleScrollend="handleScrollend"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment