Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adroit flight js version with templates and dependencies #3

Open
wants to merge 1 commit into
base: adroit-flight-js
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion generators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"list-files": "^1.1.3",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"recursive-readdir": "^2.2.1"
"recursive-readdir": "^2.2.1",
"flight-with-child-components": "4.1.0",
"flight-with-resources": "3.0.0",
"flight-with-state": "8.1.0",
"flightjs": "1.5.2"
}
}
188 changes: 43 additions & 145 deletions generators/templates/template.js
Original file line number Diff line number Diff line change
@@ -1,154 +1,52 @@
/**
* @module {component-name}
* @version {version}
* @since {date}
* @module bootstrap-sample
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these values should be dynamic

* @version 1.0.0
* @since Thu Mar 08 2018
*/

// dependencies
import './{component-name}.hbs';
import './{component-name}.scss';

const compRegisterRef = require('lib/component-register');

const { registerComponent } = compRegisterRef;

/**
* The definition of the component. Each DOM element will
* define the elements class with this string.
* @type {string}
*/
export const componentReference = 'app-js__{component-name}';

/**
* The style definition of the component.
* @type {string}
*/
export const styleDefinition = '{component-name}';

/**
* Factory method to create an instance. Linked to an html element.
*
* @return {object} Component instance.
*/
const flight = require('flightjs');
// other dependencies
/*
if needed we can add flight-with-state,
flight-with-resources, flight-with-child-components etc
*/

/* Component definition */
function create{separate-component-name}Instance() {
/**
* Component instance.
* @type {Object}
*/
const instance = {};

/**
* By setting `instance.domRefs` the baseComponent will replace the value
* of each keys in `instance.domRefs.first` with single elements found
* in `instance.element`. Same for `instance.domRefs.all`, but each key
* will have an array of elements.
*
* `first` example: The value of `childEl` will be a `HTMLElement`
* `all` example: The value of `rows` will be an `Array` of `HTMLElement`
* @type {Object}
*/
// instance.domRefs = {
// definition: styleDefinition,
// first: {
// childEl: '__child'
// },
// all: {
// rows: '__row'
// }
// };

/** @type {Object} */
// const singleRefs = instance.domRefs.first;

/** @type {Object} */
// const listRefs = instance.domRefs.all;

/**
* `created` is called before `attached`. Can be used to pass data to
* childrens `params` property.
*/
// instance.created = () => {
// forEach(instance.children, updateChildParams);
// };

/**
* Update the `instance.params` for `childInstance`.
*
* @param {object} childInstance
*/
// function updateChildParams(childInstance) {
// childInstance.receiveNewParams({
// id: instance.attribute.id,
// updateId: onIdChanged
// });
// }

/**
* The `instance.params` object was changed from parent calling `instance.receiveNewParams`.
* Properties and callback functions can be dealt with or passed down to
* child components.
*/
// instance.onNewParamsReceived = () => {
// forEach(instance.children, child => {
// child.receiveNewParams({
// updateId: instance.params.updateId
// });
// });
// };

/**
* Initialize any DOM elements which can be found within the hbs file for
* this component.
*/
function initDOMReferences() {
// myEl = domUtil.findFirst('.'
// .concat(exports.styleDefinition)
// .concat('__my-el'),
// instance.element
// );
}

/**
* Logic to run when component is ready
*/
function init() {}

/**
* Append listeners to the element.
*/
function addListeners() {
// TODO remove inline comments, just example code.
// To attach an event, use one of the following methods.
// No need remove the listener in `instance.detached`
// instance.addEventListener('click', onClick); //attached to `instance.element`
// instance.addEventListener('click', onClick, myEl); //attached to `myEl`
}

/**
* Dealloc variables and removes any added listeners.
*/
function dispose() {}

/**
* The DOM Element was added to the DOM.
*/
instance.attached = () => {
initDOMReferences();
init();
addListeners();
};

/**
* The DOM Element was removed from the DOM.
* Dealloc variables and removes any added listeners that was NOT added
* through `instance.addEventListener`.
*/
instance.detached = () => {
// console.log('detached!', instance.element);
dispose();
// add attributes here
this.attributes({
// selectors
// helloText: '.{component-name}__js-elem',
// variables
// someVariable: 1
});

/* initialize the states you want to add
Include flight-with-state on top
*/
/* this.initialState({
sampleState: true
}); */

// custom methods
/* this.customMethod = function () {
alert(this.select('helloText').html());
}; */

// add event listeners to the component
this.addListeners = function () {
/* this.on('click', {
helloText: this.customMethod
}); */
};

return instance;
// after initializing the component
this.after('initialize', function () {
this.addListeners();
});
}

registerComponent(componentReference, create{separate-component-name}Instance);
/* Creat & Attach the component to a DOM node */
const componentInstance = flight.component(create{separate-component-name}Instance);
componentInstance.attachTo('.app-js__{component-name}');
Loading