Skip to content

Instantly share code, notes, and snippets.

@jpommerening
Last active April 26, 2017 15:26
Show Gist options
  • Save jpommerening/d4f84ac2d0cab171553574cda517d925 to your computer and use it in GitHub Desktop.
Save jpommerening/d4f84ac2d0cab171553574cda517d925 to your computer and use it in GitHub Desktop.
Flow types for widgets
{
"presets": [
[ "es2015", { "modules": false } ],
[ "flow" ]
],
"plugins": [
"transform-object-rest-spread"
]
}
[ignore]
[include]
[libs]
[options]
/**
* Copyright 2017 aixigo AG
* Released under the MIT license.
* http://laxarjs.org/license
* @flow
*/
export const injections = [ 'axFeatures' ];
declare type HeadlineWidgetFeatures = {
headline: { htmlText: string },
intro: { htmlText?: string }
};
export function create( features: HeadlineWidgetFeatures ) {
return {
onDomAvailable( dom: HTMLElement ) {
[ 'headline', 'intro' ].forEach( feature => {
const html = features[ feature ].htmlText;
const element = dom.querySelector( `.${feature}-html-text` );
if( !element ) {
return;
}
if( html ) {
element.innerHTML = html;
}
else {
element.remove();
}
} );
}
};
}
{
"scripts": {
"flow": "flow ."
},
"devDependencies": {
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-flow": "^6.23.0",
"flow-bin": "^0.44.2"
}
}
@jpommerening
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment