-
Notifications
You must be signed in to change notification settings - Fork 8
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
ravisethia
wants to merge
1
commit into
karthik2706:adroit-flight-js
Choose a base branch
from
ravisethia:master
base: adroit-flight-js
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,154 +1,52 @@ | ||
/** | ||
* @module {component-name} | ||
* @version {version} | ||
* @since {date} | ||
* @module bootstrap-sample | ||
* @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}'); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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