0.0.58 • Published 8 years ago

awesome-webcomponents v0.0.58

Weekly downloads
58
License
SEE LICENSE IN LI...
Repository
github
Last release
8 years ago

awesome : object

Awesome-Webcomponents

Awesome ES6 compliant web componants for use in your app or website.

Tested and working on :

Firefox >=45 supports evrything needed with the included ./bower_components/document-register-element/build/document-register-element.js. IE Edge Array.prototype.includes polyfill is build into awesome.js

install awesome-webcomponents via bower for your project by running bower install awesome-webcomponents don't forget to run bower update on occasion to get the latest version!

Working Component Examples and Demos

awesome-webcomponents on github.io

Licensed under DBAD license

See the DBAD license in your language or our licence.md file.

Contributing

  1. Fork the repo
  2. Do awesome stuff!
  3. Submit a Pull Request
  4. Feel Awesome!

Awesome.js Class api

window.awesome = new Awesome; is called automatically to instantiate a global awesome object for your use right away.


Kind: global namespace
Properties

NameTypeDescription
awesome.pathStringPath to folder awesome.js is located in
awesome.bowerStringpath to bower components
constantsObjectawesome constants
constants.componentsShallowMergeObjectshallow merge for awesome.constants.components
constants.storesShallowMergeObjectshallow merge for awesome.constants.stores
constants.actionsShallowMergeObjectshallow merge for awesome.constants.actions
configDeepMergeObjectdeep recursive merge for awesome config object
languageObjectawesome language objects
language.defaultObjectawesome default language object
language.currentObjectawesome language object merged default and desiredLanguage
language.*Objectawesome language objects for specific languages like awesome.language.en or awesome.language.ru
setLanguagefunctionset the current language
dynamicLanguageStringfunctiona way to pass variables to language strings. This is helpful when you support languages with a variety of grammatical structures
dispatchersObjectdispatchers for store/action/component messages
storesObjectregistered awesome.Store instances. These are designed to support 1 way data flows for use by components
StoreClassStore class, used to create new stores
loadTemplatefunctionfetches nested template contents for inclusion in awesome-component
requireScriptfunctioninject script tag into header
requireCSSfunctioninject stylesheet link tag into header
mergeDatasetfunctionmerges element's data-* attributes with the defaults for that component element
updateAttributesFromDatafunctionmaps data- values to attribute values
uniqueEntriesfunctionensures that keys and values of an object unique

awesome.Store

Kind: static class of awesome
Properties

NameTypeDescription
stateObjectstate data of store exposed for reading by components via expose. The store modifies this as a shallow merge Object.
defaultStateObjectdefault store state
ignoreResetEventBooleanflag to ignore the global reset event USE WITH CAUTION
resetStatefunctionrests the store state
exposefunctionregisters the read-only state with awesome.storesstore name for components to use

Store.state : Object

state data of store exposed for reading by components via expose. The store modifies this as a shallow merge Object.

Kind: static property of Store
Access: protected
Example

//set the store state with a shallow merge
 myStoreState = {
  	property: 'prop'
 }
 store.state = myStoreState;

//get the store state
 const state = store.state

Store.defaultState : Object

default store state

Kind: static property of Store
Example

//set your default store
store.defaultState = {
 	defaultProperty1: 'red',
 	defaultProperty2: 'white',
 	defaultPropertyN: 'mandalorian'
}

Store.ignoreResetEvent : Boolean

flag to ignore the global reset event USE WITH CAUTION

Kind: static property of Store
Example

//ignore the global reset event
 store.ignoreResetEvent = true;

Store.expose(instance, name)

registers the read-only state with awesome.storesstore name for components to use

Kind: static method of Store

ParamTypeDescription
instanceStoreyour instantiated Store instance
nameStringThe name of your store

Example

//expose your store
store.expose(yourStoreScope, 'yourStoreName');

Store.resetState(events)

rests the store state

Kind: static method of Store

ParamTypeDescription
eventsObjectyour stores event-pubsub instance

Example

//reset the store state
store.resetState();

"change"

Store.state change event used to notify component that the store state has changed.

Kind: event emitted by Store

awesome.path : String

Path to folder awesome.js is located in.

Kind: static property of awesome
Access: protected
Example

//use awesome.path to reference the awesome-webcomponents directory
awesome.requireCSS(`${awesome.path}components/buttons/awesome-buttonset.css`);
awesome.requireScript(`${awesome.path}components/buttons/awesome-buttonset.js`);

awesome.constants : Object

extensible/overwriteable constansts used in awesome apps

Kind: static property of awesome
Properties

NameTypeDescription
actionObjectaction constants
storeObjectstore constants
componentObjectcomponent constants

constants.action : Object

Shallow merge action constants object

Kind: static property of constants

action.RESET_STORES : EventName

all stores should reset their state

Kind: static property of action

action.FILE_LOADED : String

files loaded and available

Kind: static property of action

action.LOGOUT_REQUEST : EventName

logout request

Kind: static property of action
Memeber: awesome.constants.action.LOGOUT_REQUEST

action.LOGIN_REQUEST : EventName

login request

Kind: static property of action
Memeber: awesome.constants.action.LOGIN_REQUEST

action.getter() ⇒ ActionConstants

action constants getter

Kind: static method of action
Returns: ActionConstants - action constants
Access: protected

action.setter(constants) ⇒ ActionConstants

action constants setter : merges the current action constants and the new constants via shallow merge.

Kind: static method of action
Returns: ActionConstants - actions merged constants
Access: protected

ParamTypeDescription
constantsObjectconstants to merge

Example

//original constants
{
 	ACTION_CONSTANT1: 'actionConst1',
 	ACTION_CONSTANT2: 'actionConst2',
}
myNewConstants = {
 	NEW_CONSTANT_1: 'const1',
 	NEW_CONSTANT_2: 'const2'
}

awesome.action.constants = myNewConstants;

//action constants will now be
//awesome.constants.action
{
 	ACTION_CONSTANT1: 'actionConst1',
 	ACTION_CONSTANT2: 'actionConst2',
 	NEW_CONSTANT_1: 'const1',
 	NEW_CONSTANT_2: 'const2'
}

constants.store : Object

Shallow merge store constants object

Kind: static property of constants

store.RESET : EventName

all stores should reset their state

Kind: static property of store

store.LOGIN_ERROR : EventName

user supplied bad credentials

Kind: static property of store

store.LOGOUT_ERROR : EventName

there was an error logging out

Kind: static property of store

store.LOGIN_SUCCESS : EventName

login was successful

Kind: static property of store

store.LOGOUT_SUCCESS : EventName

logout was successful

Kind: static property of store

store.FILE_LIST : String

file list available

Kind: static property of store

store.getter() ⇒ StoreConstants

store constants getter

Kind: static method of store
Returns: StoreConstants - store constants
Access: protected

store.setter(constants) ⇒ StoreConstants

action constants setter : merges the current store constants and the new constants via shallow merge.

Kind: static method of store
Returns: StoreConstants - stores merged constants
Access: protected

ParamTypeDescription
constantsObjectconstants to merge

Example

//original constants
{
 	STORE_CONSTANT1: 'actionConst1',
 	STORE_CONSTANT2: 'actionConst2',
}

myNewConstants = {
 	NEW_CONSTANT_1: 'const1',
 	NEW_CONSTANT_2: 'const2'
}

awesome.constantants.store = myNewConstants;

//action constants will now be
//awesome.constants.store
{
 	STORE_CONSTANT1: 'actionConst1',
 	STORE_CONSTANT2: 'actionConst2',
 	NEW_CONSTANT_1: 'const1',
 	NEW_CONSTANT_2: 'const2'
}

constants.component : Object

Shallow merge constants constants object *

Kind: static property of constants

component.VALIDATE_USERNAME : EventName

regular expression for validating user name

Kind: static property of component
Memeber: awesome.constants.component.VALIDATE_USERNAME
Example

const constanst = awesome.constansts.components;

//input pattern for a valid username, alphanumeric
<input class = 'yourUserNameInput'
 	pattern = constansts.VALIDATE_EMAIL
></input>
// a user submission of userName will not be accepter but rather userName@group would

component.VALIDATE_EMAIL : EventName

regular expression for validating user email

Kind: static property of component
Memeber: awesome.constansts.component.VALIDATE_EMAIL
Example

const constanst = awesome.constansts.components;

//input patter for a valid email address, alphanumeric
<input class = 'yourEmailInput'
 	pattern = constansts.VALIDATE_EMAIL
></input>
// an email submission of user@site will not be accepted but rather user@site.company would

component.VALIDATE_URL : EventName

regular expression for validating url

Kind: static property of component
Memeber: awesome.constansts.component.VALIDATE_URL
Example

const constanst = awesome.constansts.components;

//input pattern for a valid url
<input
 	pattern = constansts.VALIDATE_URL
></input>
// a url submission of www.nodejs.org would not be accepter but rather
// https://nodejs.org or http://www.yourSite.yourDomain

component.getter() ⇒ ComponentConstants

component constants getter

Kind: static method of component
Returns: ComponentConstants - component constants
Access: protected

component.setter(constants) ⇒ ComponentConstants

component constants setter : merges the current component constants and the new constants via shallow merge.

Kind: static method of component
Returns: ComponentConstants - components merged constants
Access: protected

ParamTypeDescription
constantsObjectconstants to merge

Example

//original constants
{
 	COMPONENT_CONSTANT1: 'actionConst1',
 	COMPONENT_CONSTANT2: 'actionConst2',
}

myNewConstants = {
 	NEW_CONSTANT_1: 'const1',
 	NEW_CONSTANT_2: 'const2'
}

awesome.constants.components = myNewConstants;

//action constants will now be
//awesome.constants.component
{
 	COMPONENT_CONSTANT1: 'actionConst1',
 	COMPONENT_CONSTANT2: 'actionConst2',
 	NEW_CONSTANT_1: 'const1',
 	NEW_CONSTANT_2: 'const2'
}

awesome.config : Object

extensible/overwriteable constansts used in awesome apps

Kind: static property of awesome

config.setter() ⇒ Object

Deep merge config object

Kind: static method of config
Returns: Object - awesome.config
Example

// awesome.config could be
{
    a:1,
    b:{
        c:3
    },
    d:{
        e:55,
        f:{
            g:99
        }
    },
    q:{
        r:77
    }
}

awesome.configMerge(
    {
        b:{
            x:{
                y:{
                    z:99999
                }
            }
        },         *
        d:{
            f:{
                h:55
            }
        },
        q:33
    }
)


//now awesome.config would look like
{
    a:1,
    b:{
        c:3
            x:{
                y:{
                    z:99999
                }
            }
        }
    },
    d:{
        e:55,
        f:{
            g:99,
            h:55
        }
    },
    q:33
}

awesome.language : Object

language objects used by awesome components

Kind: static property of awesome

awesome.dispatchers : Object

dispatchers for awesome 1 way data flow

Kind: static property of awesome
Access: protected
Properties

NameTypeDescription
actionObjectaction dispatcher
storeObjectstore dispatcher
componentObjectcomponent dispatcher

dispatchers.action : EventEmitter

awesome dispatcher for actions, uses event-pubsub

Kind: static property of dispatchers
Properties

NameTypeDescription
onfunctionbinds handler to action event
offfunctionunbinds handler from action event
triggerfunctionfires store event

Example

const dispatcher = awesome.dispatchers.action;
const constants = awesome.constants;

//trigger an event to store
dispatcher.trigger(
 	constants.store.YOUR_STORE_CONSTANT,
 	{
 		data1 : 'data1',
 		data2 : 'data2'
 	}
);

//listen to an event from a component
dispatcher.on(
 	constants.components.YOUR_COMPONENT_CONSTANT,
 	yourHanderFunction
);

//stop listening to the event
dispatcher.off(
 	constants.components.YOUR_COMPONENT_CONSTANT,
 	yourHanderFunction
);

dispatchers.component : EventEmitter

awesome dispatcher for components, uses event-pubsub

Kind: static property of dispatchers
Properties

NameTypeDescription
triggerfunctionfires action event

Example

const dispatcher = awesome.dispatcher.component;
const constants = awesome.constants;

//trigger an event to action
dispatcher.trigger(
 	constants.action.YOUR_COMPONENT_CONSTANT,
 	{
 		data1 : 'data1',
 		data2 : 'data2'
 	}
);

dispatchers.store : EventEmitter

awesome dispatcher for stores, uses event-pubsub

Kind: static property of dispatchers
Properties

NameTypeDescription
onfunctionbinds handler to store events
offfunctionunbinds handler from store event
eventsfunctionfires event

Example

const dispatcher = awesome.dispatcher.store;
const constants = awesome.constants;

//listen to an event from an action
dispatcher.on(
 	constants.action.YOUR_STORE_CONSTANT,
 	yourHanderFunction
);

//stop listening to the event
 dispatcher.off(
 	constants.components.YOUR_STORE_CONSTANT,
 	yourHanderFunction
);

awesome.stores : Object

awesome 1 way data flow stores for use by component

Kind: static property of awesome
Example

state=awesome.stores.auth.state;

state.on(
  	'change',
  	this.yourAwesomeUpdateHandler.bind(this)
);

awesome.bower : String

Path to bower components

Kind: static property of awesome
Access: protected
Example

//include bower components using the bower components path
awesome.requireScript(`${awesome.bower}bower-component/bower-component.js`);

awesome.loadTemplate(instance) ⇒ Object

loadTemplate collects template element and returns element

Kind: static method of awesome
Returns: Object - contents of template element
Access: protected

ParamTypeDescription
instanceObjectinstance or scope of template element

Example

//taken from awesome-list example, loadTemplate will load template element of awesome-component
//and returns element

//html snippet

 <awesome-list>
       <template>
           <li>
               Test 1
           </li>
           <li>
               Test 2
           </li>
           <li>
               Test 3
           </li>
       </template>
   </awesome-list>

//js

const content=awesome.loadTemplate(this);

//constents of content
       `<li>
           Test 1
       </li>
       <li>
           Test 2
       </li>
       <li>
           Test 3
       </li>`

//usage
//this content can now be loaded into awesome-list

this.innerHTML=`
    <ul>
        ${content}
    </ul>
`;

awesome.requireScript(path) ⇒ Boolean

requireScript appends scripts to the docuyment head with a differed false

Kind: static method of awesome
Returns: Boolean - true
Access: protected

ParamTypeDescription
pathStringpath to script

Example

//here we require the dispatcher to action and the constants to stores and actions
awesome.requireScript(`${awesome.path}dispatchers/action.js`);
awesome.requireScript(`${awesome.path}actions/constants.js`);
awesome.requireScript(`${awesome.path}stores/constants.js`);

awesome.requireScript(path) ⇒ Boolean

requireLanguage includes js scripts into document

Kind: static method of awesome
Returns: Boolean - true
Access: protected

ParamTypeDescription
pathStringpath to script

awesome.requireCSS(path) ⇒ Boolean

requireCSS requires and appends scripts to CSS head

Kind: static method of awesome
Returns: Boolean - false if stylesheet has already been loaded into document

ParamTypeDescription
pathStringPath to CSS stylesheet

Example

//require any CSS to script
awesome.requireCSS(`${awesome.path}components/your-component/your-component.css`);

awesome.mergeDataset(el, defaults)

mergeDataset merges element's dataset to current default dataset of document

Kind: static method of awesome

ParamTypeDescription
elHTMLElementelement with dataset to be merged
defaultsObjectdefault dataset

Example

defaultElementDataset = {
 	property1: 'one',
 	property2: 'two'
}

function componentCreatedCallback(componentDataset){
		mergeDataset(myElement, componentDataset);
}

//after the component is created it will contain
//ElementDataset
 {
 	property1 : 'newProp1',
 	property2 : 'newProp2'
 }

awesome.updateAttributesFromData(el, key, value) ⇒ HTMLElement

updateAttributesFromData updates an element's attributes

Kind: static method of awesome
Returns: HTMLElement - updated element object

ParamTypeDescription
elHTMLElementelement object
keyStringkey of element
valueStringvalue to update data to

Example

//orginal element attributes
{
 	attribute1 : 'green',
 	attribute2 : 'red',
 	attribute3 : 'white'
}

yourElementAttributeUpdater(element, attribute3, black);

function yourElementAttributeUpdater(element, elementKey,newValue){
 	awesome.updateAttributesFromData(element, elementKey, newValue);
}

//resulting element attributes
{
 	attribute1 : 'green',
 	attribute2 : 'red',
 	attribute3 : 'black'
}

awesome.uniqueEntries(data) ⇒ Boolean

uniqueEntries ensures that keys and values of data array are unique

Kind: static method of awesome
Returns: Boolean - true

ParamTypeDescription
dataObjectData object or array with unique entries

Example

//check that your constants all have unique entries as they should
 const constans = awesome.constans;

awesome.uniqueEntries(constans.store);
awesome.uniqueEntries(constans.components);
awesome.uniqueEntries(constans.actions);

//if entires are not unique an error will be thrown
`duplicate key of yourKey const keys mist be unique!`
//or
`duplicate value of yourConstant found on yourKey and yourKeyDuplicate const value strings MUST be unique!`

"awesome-language-set" (e)

emitted when the language is set or changed via awesome.setLanguage.

Kind: event emitted by awesome

ParamTypeDescription
eEventEvent Data
e.detailStringlanguageCode

"awesome-script-loaded" (e)

emitted when a script included via requireScript has completed loading a script.

Kind: event emitted by awesome

ParamTypeDescription
eEventEvent Data
e.detailStringpath of the loaded script

Example

window.on(
 	'awesome-script-loaded',
 	yourAwesomeLoadedHandler
);

"awesome-script-error" (e)

emitted when a script included via requireScript can NOT be loaded.

Kind: event emitted by awesome

ParamTypeDescription
eEventEvent Data
e.detailStringpath of the loaded script

"awesome-language-loaded" (e)

emitted when a new language file included via awesome.requireLanguage has completed loading.

Kind: event emitted by awesome

ParamTypeDescription
eEventEvent Data
e.detailStringpath of the loaded language

"awesome-ready"

emitted when all queued scripts included via requireScript have completed loading. This will fire each time awesome deems it is ready for use. So if you include more scripts long after load it will fire again once all the new scripts are loaded.

Kind: event emitted by awesome

"awesome-wants-lang" (e)

emitted when a language check is performed for the first time and the language script is NOT in the head. This is useful when you have your own language files to load.

Kind: event emitted by awesome

ParamTypeDescription
eEventEvent Data
e.detailStringdesired language code

setLanguage(languageCode)

Merge a specific language and the default languages. If the languageCode has not been populated on the awesome.language object, the awesome.language.default will be used.

Kind: global function

ParamTypeDescription
languageCodeStringlike 'en', 'en-US', 'es' or 'zh' etc.

Example

//if awesome.language.default is
{
    hello:'Hello',
    appName:'My Awesome App'
}

//and awesome.language.es is
{
    hello:'Ola'
}

awesome.setLanguage('es');

//will result in awesome.language.current being
{
    hello:'Ola',
    appName:'My Awesome App'
}
0.0.58

8 years ago

0.0.50

8 years ago

0.0.49

8 years ago

0.0.37

8 years ago

0.0.35

8 years ago

0.0.24

8 years ago

0.0.16

8 years ago

0.0.14

8 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.1

8 years ago

0.0.0

8 years ago