A few frills anti-framework for use in electron, no thought or care has been given to any other environment or use case.
Api of models and views and such inspired by ampersand.js.
The statemachine is somewhat based on the api of machina.js.
To take a look at some of the core stuff and some hot widget action
npm i
npm run examples
Then stroll on over to chrome / chromium and take a look.
Coming Soon: Full Electron example
- MuDialogue
Abstract dialogue class for use in MuDialogueManager
- MuManager
A simple place to store anything if so desired, if an object is stored with a property 'classDef', it will be treated as a reference to a class / called with new and stored under the given key, with remaining properties passed in as options. Use it or don't, I have no feelings either way. Good place to keep shit out of global scope.
- MuPage
Abstract class for page controllers
- MuPageManager ⇐
MuEvent
Super fun tool here. Designate by default some element with the attribute mu-root, and one or more elements inside that one mu-page='pagename' mu-controller='someFnWithHandlers'. Then fire this badboy up, and call load with 'pagename' bam
- MuState
Abstract State class for use in MuStateMachine
- MuStateMachine
Super neat statemachine, very loosely based on machina.js, this is no where near as frilly, this does not have a kitchen sink, nor will it keep your beverages cold.
- MuCollection ⇐
MuEvent
A collection emitting events on certain actions
- MuPagedCollection ⇐
MuCollection
Uses MuPaginator to paginate a MuCollection, why would you want to do this? I dunno, you're the one using it.
- MuCollectionView ⇐
MuWrapperView
Generic view wrapper for a collection
- MuPaginatedCollectionView ⇐
MuCollectionView
View wrapper for a paginated collection
- MuWrapperView ⇐
MuEvent
Abstract class for wrapping more complex constructs.
- MuView ⇐
MuEvent
Main class for for a 'view', examples in example folder
- MuTagen
Programmatically create some html fragment template
- MuBroker
Simple Broker for messaging to increase decoupling, supports history in case a consumer hasn't been registered, before messages are published to channel
- MuEvent
Very simple no frills Event Emitter so to speak, might add emitter.once later
- MuNodeManager
Name, store and possibly clone / possibly remove arbitrary nodes of your document for later retrieval. Pretty fancy right?
- MuPaginator
Class for 'paginating' an array
- MuObservableObject()
A mystical thing, uses traps to watch for changes to an object, also has derived properties.
- muView()
Factory function for MuView, uses currying to allow default options, calling result with final options to produce instances.
- muCss(style, id)
Inject a style sheet, if you feel so inclined
- muDom(selector, context)
A cheap, light weight jquery-ish knockoff
Abstract dialogue class for use in MuDialogueManager
A simple place to store anything if so desired, if an object is stored with a property 'classDef', it will be treated as a reference to a class / called with new and stored under the given key, with remaining properties passed in as options. Use it or don't, I have no feelings either way. Good place to keep shit out of global scope.
Kind: global class
Make a manager object
Add a property
Kind: instance method of MuManager
Param | Type | Description |
---|---|---|
name | String |
key to store whatever you are storing under |
opts | * |
Whatever you are storing, if it has a property classDef, that property will be called with new, and the rest of the object as arguments to it. |
Retrieve a thing you have stored
Kind: instance method of MuManager
Param | Type | Description |
---|---|---|
name | String |
key to retrieve |
Abstract class for page controllers
Kind: global class
This is always called by super in extending class don't worry about it...
Param | Type | Description |
---|---|---|
options | Object |
Just two options |
options.pageName | String |
Name of the page |
options.pageManager | MuPageManager |
Reference to the MuPageManager managing this page |
Handler for load:pageName, subclass may implement
Kind: instance method of MuPage
Handler for show:pageName, subclass may implement
Kind: instance method of MuPage
Handler for hide:pageName, subclass may implement
Kind: instance method of MuPage
MuPageManager ⇐ MuEvent
Super fun tool here. Designate by default some element with the attribute mu-root, and one or more elements inside that one mu-page='pagename' mu-controller='someFnWithHandlers'. Then fire this badboy up, and call load with 'pagename' bam
Kind: global class
Extends: MuEvent
Param | Type | Description |
---|---|---|
options | Object |
Options |
options.root | String |
The name of the attribute denoting the root of your page. Where to find pages, and where page swapping will occur in essence. Defaults to 'mu-root'. |
options.pageAttribute | String |
The name of the attribute denoting a page. These will be cloned and removed from the dom. Defaults to 'mu-page'. |
options.controllerAttribute | String |
Placed on same element you denoted as a page. This should be a class name, to be instantiated by MuPageManager during init. |
options.options | Object |
Options you want passed in to each page controller, in addition to the defaults passed into each pageManager: a reference to this, and name: its name |
Get a list of attributes of the page
Kind: instance method of MuPageManager
Param | Type | Description |
---|---|---|
name | String |
Name of page to get attributes of. |
Get a reference to the DOM node tied to specified page
Kind: instance method of MuPageManager
Param | Type | Description |
---|---|---|
name | String |
Name of page |
Get the controller instance bound to specified page
Kind: instance method of MuPageManager
Param | Type | Description |
---|---|---|
name | String |
Name of page |
After construction, this is probably the only method you will be using. Removes old page if any emitting hide:pageName so that it knows it is being removed from the dom. If it is the first time this page has been loaded load:pageName is emitted in place of show:pageName, allowing your controller to do prep work if needed, you might want to call show yourself at the end of your handler for show, depending on how all your shit is setup.
Kind: instance method of MuPageManager
Param | Type | Description |
---|---|---|
name | String |
Name of page |
Method to register a listener
Kind: instance method of MuPageManager
Overrides: on
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
May or may not work, usually just clear all listeners if anything
Kind: instance method of MuPageManager
Overrides: removeListener
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
Clears all listeners
Kind: instance method of MuPageManager
Overrides: clearListeners
Emit event
Kind: instance method of MuPageManager
Overrides: emit
Param | Type | Description |
---|---|---|
event | String |
Name of event to emit |
Abstract State class for use in MuStateMachine
Super neat statemachine, very loosely based on machina.js, this is no where near as frilly, this does not have a kitchen sink, nor will it keep your beverages cold.
Kind: global class
So basically you only need to define some states, of which there is one 'special' state you can add 'uninitialized' if you don't add it a blank MuState is used.
Each state can also have its own '*' handler as well to respond to calls not specifically covered in that state's definition.
Every property not under states:{}, becomes a property of the instance.
Param | Type | Description |
---|---|---|
options | Object |
options for your stateMachine, everything not under options.state becomes a property of the instance |
options.states | Object |
defines the states your machine can transition to |
Bare bones ability to add states dynamically after initialization. Will overwrite things if that is what you meant to do, or will overwrite them even if you didn't mean to do that.
Kind: instance method of MuStateMachine
Param | Type | Description |
---|---|---|
name | String |
name of the state |
stateDef | Object |
state definition |
Attempt to transition to a state. Should probably be called from the api / internally, but again whatever it's your code.
Kind: instance method of MuStateMachine
Param | Type | Description |
---|---|---|
name | String |
Name of state to transition to. |
Attempts to call 'name' on current state. Should probably be called from your provided api, instead of attempting to call directly from outside
Kind: instance method of MuStateMachine
Param | Type | Description |
---|---|---|
name | String |
state's method you are attempting to call |
MuCollection ⇐ MuEvent
A collection emitting events on certain actions
Kind: global class
Extends: MuEvent
Create a new collection, in the future will optionally wrap items in a model. for exceptionally large collections, use flat, so as to not add each 'item' to this.collection[item.idField] = item. Can be very slow. Flat instead stores this.collection as an array, no removal of elements, just reset.
Param | Type | Description |
---|---|---|
options | Object |
Options for the collection |
options.flat | Boolean |
Store as array, not k:v |
options.idField | String |
The field to use as k when not flat, defaults to 'id' |
options.model | MuObservableObject |
Future: non instantiated model to wrap each item |
options.comparator | function |
Some fn to aid in sorting |
options.content | Array |
Initial items in collection, will fire add events, but you will be unable to listen |
Example
myCollection = new MuCollection({idField: 'customId'})
// or
myCollection = new MuCollection({flat: true})
myCollection.on('add',someFn)
myCollection.add([{foo: 'a'},{foo: 'b'}])
// someFn called twice with item, or
myCollection.add([{foo: 'a'},{foo: 'b'}],true)
// no add event fired, instead 'bulk' event fired after all items added
Convenience function for add(stuff,true)
Kind: instance method of MuCollection
Param | Type | Description |
---|---|---|
items | Array | SingleItem |
Stuff to add |
Perhaps the most useful method on a collection, adding things to the collection
Kind: instance method of MuCollection
Param | Type | Default | Description |
---|---|---|---|
items | Array | SingleItem |
Stuff to add | |
bulk | Boolean |
false |
Skip emitting add for each item, emit 'bulk' |
Sort the collection, may or may not work, haven't tested it in any real manner
Kind: instance method of MuCollection
Param | Type | Default | Description |
---|---|---|---|
comparator | function |
Some function that sorts things | |
reverse | Boolean |
false |
Sorting direction |
Removes item / items from collection, throws an error if collection is flat
Kind: instance method of MuCollection
Param | Type | Description |
---|---|---|
idxs | Array | SingleItem |
A single index/key or array of them |
Get Item from collection by idField or by index if flat
Kind: instance method of MuCollection
Param | Type | Description |
---|---|---|
id | String | Number |
A string key for idField lookup or number for flat index |
Do something with each thing in this collection...duh
Kind: instance method of MuCollection
Param | Type | Description |
---|---|---|
fn | function |
A thing to do to each item in this collection |
Reset internal state to a collection with no items or with items passed in
Kind: instance method of MuCollection
Param | Type | Description |
---|---|---|
items | Array | SingleItem |
Stuff to add to newly cleared collection |
Method to register a listener
Kind: instance method of MuCollection
Overrides: on
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
May or may not work, usually just clear all listeners if anything
Kind: instance method of MuCollection
Overrides: removeListener
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
Clears all listeners
Kind: instance method of MuCollection
Overrides: clearListeners
Emit event
Kind: instance method of MuCollection
Overrides: emit
Param | Type | Description |
---|---|---|
event | String |
Name of event to emit |
MuPagedCollection ⇐ MuCollection
Uses MuPaginator to paginate a MuCollection, why would you want to do this? I dunno, you're the one using it.
Kind: global class
Extends: MuCollection
- MuPagedCollection ⇐
MuCollection
- new MuPagedCollection(options)
- .setPageSize(n)
- .getPageSize()
- .maxPage()
- .currentPageNumber()
- .currentPage()
- .getPage(n)
- .nextPage()
- .previousPage()
- .lastPage()
- .firstPage()
- .addBulk(items)
- .add(items, bulk)
- .sort(comparator, reverse)
- .remove(idxs)
- .get(id)
- .each(fn)
- .reset(items)
- .on(event, fn)
- .removeListener(event, fn)
- .clearListeners()
- .emit(event)
This is where shit gets real, ok that might be an overstatement. Basically this provides an api for MuPaginator and special events pertaining to a paged collection
Param | Type | Description |
---|---|---|
options | Object |
Options for the collection |
options.flat | Boolean |
Store as array, not k:v |
options.idField | String |
The field to use as k when not flat, defaults to 'id' |
options.model | MuObservableObject |
Future: non instantiated model to wrap each item |
options.comparator | function |
Some fn to aid in sorting |
options.content | Array |
Initial items in collection, will fire add events, but you will be unable to listen |
Sets the number of items per 'page'
Kind: instance method of MuPagedCollection
Param | Type | Description |
---|---|---|
n | Integer |
Number of items per page |
Gets the current page size
Kind: instance method of MuPagedCollection
Gets maximum possible page number with current collection
Kind: instance method of MuPagedCollection
Gets the current page number
Kind: instance method of MuPagedCollection
Gets a reference to current page
Kind: instance method of MuPagedCollection
Gets specified page number, if out of range gets first or last page
Kind: instance method of MuPagedCollection
Param | Type | Description |
---|---|---|
n | Integer |
Page number to get |
Gets the next page
Kind: instance method of MuPagedCollection
Gets previous page
Kind: instance method of MuPagedCollection
Gets last page
Kind: instance method of MuPagedCollection
Gets first page
Kind: instance method of MuPagedCollection
Convenience function for add(stuff,true)
Kind: instance method of MuPagedCollection
Overrides: addBulk
Param | Type | Description |
---|---|---|
items | Array | SingleItem |
Stuff to add |
Perhaps the most useful method on a collection, adding things to the collection
Kind: instance method of MuPagedCollection
Overrides: add
Param | Type | Default | Description |
---|---|---|---|
items | Array | SingleItem |
Stuff to add | |
bulk | Boolean |
false |
Skip emitting add for each item, emit 'bulk' |
Sort the collection, may or may not work, haven't tested it in any real manner
Kind: instance method of MuPagedCollection
Overrides: sort
Param | Type | Default | Description |
---|---|---|---|
comparator | function |
Some function that sorts things | |
reverse | Boolean |
false |
Sorting direction |
Removes item / items from collection, throws an error if collection is flat
Kind: instance method of MuPagedCollection
Overrides: remove
Param | Type | Description |
---|---|---|
idxs | Array | SingleItem |
A single index/key or array of them |
Get Item from collection by idField or by index if flat
Kind: instance method of MuPagedCollection
Overrides: get
Param | Type | Description |
---|---|---|
id | String | Number |
A string key for idField lookup or number for flat index |
Do something with each thing in this collection...duh
Kind: instance method of MuPagedCollection
Overrides: each
Param | Type | Description |
---|---|---|
fn | function |
A thing to do to each item in this collection |
Reset internal state to a collection with no items or with items passed in
Kind: instance method of MuPagedCollection
Overrides: reset
Param | Type | Description |
---|---|---|
items | Array | SingleItem |
Stuff to add to newly cleared collection |
Method to register a listener
Kind: instance method of MuPagedCollection
Overrides: on
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
May or may not work, usually just clear all listeners if anything
Kind: instance method of MuPagedCollection
Overrides: removeListener
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
Clears all listeners
Kind: instance method of MuPagedCollection
Overrides: clearListeners
Emit event
Kind: instance method of MuPagedCollection
Overrides: emit
Param | Type | Description |
---|---|---|
event | String |
Name of event to emit |
MuCollectionView ⇐ MuWrapperView
Generic view wrapper for a collection
Kind: global class
Extends: MuWrapperView
Stub function, extending class may implement
Kind: instance method of MuCollectionView
Overrides: init
Stub function, extending class may implement
Kind: instance method of MuCollectionView
Overrides: render
Stub function, extending class must implement
Kind: instance abstract method of MuCollectionView
Overrides: remove
Method to register a listener
Kind: instance method of MuCollectionView
Overrides: on
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
May or may not work, usually just clear all listeners if anything
Kind: instance method of MuCollectionView
Overrides: removeListener
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
Clears all listeners
Kind: instance method of MuCollectionView
Overrides: clearListeners
Emit event
Kind: instance method of MuCollectionView
Overrides: emit
Param | Type | Description |
---|---|---|
event | String |
Name of event to emit |
MuPaginatedCollectionView ⇐ MuCollectionView
View wrapper for a paginated collection
Kind: global class
Extends: MuCollectionView
Stub function, extending class may implement
Kind: instance method of MuPaginatedCollectionView
Overrides: init
Stub function, extending class may implement
Kind: instance method of MuPaginatedCollectionView
Overrides: render
Stub function, extending class must implement
Kind: instance abstract method of MuPaginatedCollectionView
Overrides: remove
Method to register a listener
Kind: instance method of MuPaginatedCollectionView
Overrides: on
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
May or may not work, usually just clear all listeners if anything
Kind: instance method of MuPaginatedCollectionView
Overrides: removeListener
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
Clears all listeners
Kind: instance method of MuPaginatedCollectionView
Overrides: clearListeners
Emit event
Kind: instance method of MuPaginatedCollectionView
Overrides: emit
Param | Type | Description |
---|---|---|
event | String |
Name of event to emit |
MuWrapperView ⇐ MuEvent
Abstract class for wrapping more complex constructs.
Kind: global class
Extends: MuEvent
Should only be called by super in extending class
Param | Type | Description |
---|---|---|
options | Object |
References to parent and root el |
options.el | The node this view manipulates | |
options.parent | The view rendering this |
Stub function, extending class may implement
Kind: instance method of MuWrapperView
Stub function, extending class may implement
Kind: instance method of MuWrapperView
Stub function, extending class must implement
Kind: instance abstract method of MuWrapperView
Method to register a listener
Kind: instance method of MuWrapperView
Overrides: on
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
May or may not work, usually just clear all listeners if anything
Kind: instance method of MuWrapperView
Overrides: removeListener
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
Clears all listeners
Kind: instance method of MuWrapperView
Overrides: clearListeners
Emit event
Kind: instance method of MuWrapperView
Overrides: emit
Param | Type | Description |
---|---|---|
event | String |
Name of event to emit |
MuView ⇐ MuEvent
Main class for for a 'view', examples in example folder
Kind: global class
Extends: MuEvent
Param | Type | Description |
---|---|---|
options | Object |
various options |
options.template | function | String |
Template to become this.el |
options.model | MuModel |
Model that bindings will use |
options.bindings | Object |
An object with model properties to watch as keys |
options.events | Object |
An object with 'event-type element > .foo' as keys and fn as value, to be bound to this.el |
options.autoRender | Boolean |
Call render at end of constructor |
Example
// overly simple non working example
let myView = new MuView({bindings: {foo: {valid action schema}...},
model: someModelWithFoo,
events: {'click some selector that exists within this.el': someFn},
references: {aDomRef: '.bar'}})
someModelWithFoo.foo = 'bar'
// result is action schema is called with new value of someModelWithFoo.foo
// clicking on element inside view.el with 'some selector that exists within this.el'
// calls someFn, someFn might use this.aDomRef to manipulate something
Kind: instance method of MuView
Param | Type | Description |
---|---|---|
references | Object |
An object describing dom references bound to 'this', and the selectors to use. Called internally. The references are mainly used inside of your event bindings, for easy access without excessive dom queries. Will handle a selector or muDom instance. |
Example
myView.references({aBtn: 'button #myButton'})
myView.aBtn.on('click',()=>{console.log('button clicked')})
Checks for special case of '*' right now. In the future, there might be more. '*' creates a new essentially derived property on the 'model' passed in. Naming said property according to the 'name' key, based of some property of the model 'prop' which should be an array. Essentially flattening a sequence of model properties to an array: [key1,key2] comes out ['foo','bar'] of a model {key1: 'foo', key2: 'bar', key3: 'baz'} this array is added to the bindings ['foo','bar'] and if [key1,key2] is changed then the binding is called again with the resulting mapped array, see rowCollectionView in muTable for use. Called internally.
Kind: instance method of MuView
Param | Type | Description |
---|---|---|
bindings | Object |
List of bindings defaults to this._bindings |
Method for binding changes in the model to actions, called internally. Currently accepts text, html, attribute and value actions on changed model prop. As well as special case '*' which is mentioned in documentation for parseBindings.
Empty string selector is view.el. Selector is required to exist.
Kind: instance method of MuView
Param | Type | Description |
---|---|---|
bindings | Object |
List of model props to bind to actions |
Example
myView.bindings({foo: {selector: 'div.foo',
type: html,
template: someFnTakingNewValueReturningHtml }})
modelPassedIntoMyViewConstructor.foo = 'bar'
// result is myView.el's div.foo is replaced with template function output
Uses event delegation to respond to events on view.el and its children. keys should follow pattern 'eventName selector'. A string with no selector, only eventName refers to view.el itself and not some child.
Place more generically selected things first: {'click': fn, 'click button': fn, 'click button.foo': fn} Called internally.
Kind: instance method of MuView
Example
myView.events({'click button.foo': ()=>{console.log('foo was clicked')}})
//clicking on button.foo logs the click to console
Adds a collection as a subview of this view, wrapping it in either a MuCollectionView or if the collection is paginated a MuPaginatedCollectionView
Kind: instance method of MuView
Param | Type | Description |
---|---|---|
options | Object |
Set of options for the collection |
options.collection | Collection |
An object conforming to collection contract |
options.view | MuView | MuWrapperView |
The result of calling muView curried function is called by MuCollectionView or MuPaginatedCollectionView per item in collection |
options.viewOptions | Object |
Merged before view is instantiated per item |
options.lookup | function |
If present is called with value of item, what it returns is used in place of item for view per item |
options.target | String |
IF supplied must be selector of some node in parent |
Example
myView.addCollection({view: someView, collection someCollection, target: 'div.foo'})
Registers a subview that knows where to insert itself into this view
Kind: instance method of MuView
Param | Type | Description |
---|---|---|
view | MuWrapperView |
A wrapped view of some kind |
Attempts to call render on all subviews
Kind: instance method of MuView
Attempts to remove first all subviews and then self from the dom
Kind: instance method of MuView
Slaps events and model bindings onto this.el and then renders subviews
Kind: instance method of MuView
Method to register a listener
Kind: instance method of MuView
Overrides: on
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
May or may not work, usually just clear all listeners if anything
Kind: instance method of MuView
Overrides: removeListener
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
Clears all listeners
Kind: instance method of MuView
Overrides: clearListeners
Emit event
Kind: instance method of MuView
Overrides: emit
Param | Type | Description |
---|---|---|
event | String |
Name of event to emit |
Programmatically create some html fragment template
Kind: global class
Get the party started
Example
let frag = new MuTagen().tag('div').class().tag('p').text('aParagraph').compile()
frag.render({class: 'foo',aParagraph: 'Some text for the paragraph'})
// returns
// <div class="foo"><p>Some text for the paragraph</p></div>
//For now lets just assume
frag = new MuTagen()
Now that the party is started, lets make a tag
Kind: instance method of MuTagen
Param | Type | Description |
---|---|---|
name | String |
Name of the tag you trying to create |
prefix | String |
Where in the data to find values for attributes / text / etc for this and nested tags |
Example
frag.tag('div')
// optionally
frag.tag('div','foo')
// When render is called later all future properties must be found under {foo:{}}
// for any tag under this level, more robust example being
frag.tag('div').class().tag('section','profile').class()
.tag('p').text('name').close()
.tag('p').text('info').close().close()
.tag('p').text('status')
frag.render({class:'foo',status:'online',profile:{ name: 'John Smith',
info: 'age: 34, likes: long walks', class: 'profile'}})
<div class="foo">
<section class="profile">
<p>John Smith</p>
<p>age: 34, likes: long walks</p>
</section>
<p>online</p>
</div>
Now we have a tag so lets add an attribute to it
Kind: instance method of MuTagen
Param | Type | Description |
---|---|---|
name | String |
Name of the attribute you trying to create |
prop | String |
Where in the data to get value for this attribute, defaults to name of attribute |
Example
frag.attribute('class')
// By default it will look up the value for the attribute later under the
// key with the same name as that attribute, or you can specify what prop
frag.attribute('class','keyToFindClassUnder')
Convenience function for frag.attribute('class')
Kind: instance method of MuTagen
Param | Type | Default | Description |
---|---|---|---|
prop | String |
class |
Where in the data to get value for this class, defaults to 'class' |
Convenience function for frag.attribute('id')
Kind: instance method of MuTagen
Param | Type | Default | Description |
---|---|---|---|
prop | String |
id |
Where in the data to get value for this id, defaults to 'id' |
Set the text for this node
Kind: instance method of MuTagen
Param | Type | Default | Description |
---|---|---|---|
prop | String |
text |
Where in the data to get the value for this text, defaults to 'text' |
Close this tag level
Kind: instance method of MuTagen
Go all the way back to the first tag that was opened
Kind: instance method of MuTagen
Now you are done adding tags and attributes etc
Kind: instance method of MuTagen
Call render now as many times as you want with data that matches what you described previously
Kind: instance method of MuTagen
Param | Type | Description |
---|---|---|
props | Object |
Data shaped as described by your calls to tag and attribute |
Simple Broker for messaging to increase decoupling, supports history in case a consumer hasn't been registered, before messages are published to channel
Kind: global class
Requires at least empty object {}
Param | Type | Description |
---|---|---|
config | Object |
configuration |
config.historyLimit | integer |
max messages to store |
Example
let broker = new MuBroker({})
broker.subscribe('test:echo',(msg,success)=>{ console.log(msg); success('it worked')})
broker.publish('test:echo','this will be echoed').then((result)=>{console.log(result)})
Method for consumers to register - will create channel if it doesn't exist
Kind: instance method of MuBroker
Param | Type | Description |
---|---|---|
name | String |
channel name to subscribe to |
receiver | function |
function handling reply |
type | String |
one of [MuBroker.SINGLE, MuBroker.PROGRESSIVE] if you know or think the channel might not exist already and need to specify type. Defaults to MuBroker.SINGLE |
Stop consuming messages with given receiver on given channel
Kind: instance method of MuBroker
Param | Type | Description |
---|---|---|
name | String |
channel name being unsubscribed from |
receiver | function |
original function handling reply |
Publish a message to a channel - will create channel if it doesn't exist
Kind: instance method of MuBroker
Param | Type | Description |
---|---|---|
name | String |
channel name being published to |
msg | Object |
Anything that you want passed to the consumer. If msg.property is defined and a function then it will be given as callback to consumer. |
type | String |
one of [MuBroker.SINGLE, MuBroker.PROGRESSIVE] if you know or think the channel might not exist already and NEED to specify type. Defaults to MuBroker.SINGLE |
Very simple no frills Event Emitter so to speak, might add emitter.once later
Kind: global class
Takes no arguments
Example
let emitter = new MuEvent()
emitter.on('whatever',()=>{console.log(whatever)})
emitter.emit('whatever')
Method to register a listener
Kind: instance method of MuEvent
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
May or may not work, usually just clear all listeners if anything
Kind: instance method of MuEvent
Param | Type | Description |
---|---|---|
event | String |
Name of event to listen for |
fn | function |
Fn to call when event heard |
Clears all listeners
Kind: instance method of MuEvent
Emit event
Kind: instance method of MuEvent
Param | Type | Description |
---|---|---|
event | String |
Name of event to emit |
Name, store and possibly clone / possibly remove arbitrary nodes of your document for later retrieval. Pretty fancy right?
Kind: global class
Nothing to see here, pretty standard instance constructor...
This is the heavy lifter here
Kind: instance method of MuNodeManager
Param | Type | Default | Description |
---|---|---|---|
name | String |
The name you want to store it under | |
selector | String |
Where to find your node | |
context | SomethingDomish |
Defaults to document | |
clone | Boolean |
true |
Clone it or just store reference, defaults to true |
Like add but it removes the node from the document after jacking it
Kind: instance method of MuNodeManager
Get a clone of something you stored earlier!!
Kind: instance method of MuNodeManager
Get a direct reference to something you stored earlier! Not as exciting as getCloned so only one !
Kind: instance method of MuNodeManager
Maybe you know what you want now, but later you won't, but you'll like, still want it, later, when you want it.
Kind: instance method of MuNodeManager
Param | Type | Default | Description |
---|---|---|---|
name | String |
Name of the node you want | |
cloned | Boolean |
true |
Defaults to true, if false gets raw node reference, not clone... |
Class for 'paginating' an array
Kind: global class
Set a pagesize and pass in some data, if you reset or change data from outside you should probably go ahead and set instance.paginate to undefined before getting next page or change current page...or really do whatever to get your desired result
Param | Type | Description |
---|---|---|
options | Object |
Options for paginator |
options.pageSize | Integer |
Items to return per page |
options.data | Array |
An array to paginate, yay! |
Example
let p = new MuPaginator({pageSize: 2, data: [1,2,3,4,5,6,7,8,9,10]})
console.log(p.nextPage())
// [3,4]
Internal generator function, for the actual paginating, cause why the hell not
Kind: instance method of MuPaginator
Does pretty much all of the work, returns a page by pagenumber.
Kind: instance method of MuPaginator
Param | Type | Description |
---|---|---|
pageNumber | Integer |
defaults to this.currentPage if not provided |
Returns the max possible page number
Kind: instance method of MuPaginator
Are we on the last page?
Kind: instance method of MuPaginator
If we weren't, we are now, on the last page that is.
Kind: instance method of MuPaginator
Similar to lastPage except by some miracle, gets you the first page
Kind: instance method of MuPaginator
Now this one is unique, it gets you the next page
Kind: instance method of MuPaginator
Ok I lied nextPage wasn't that unique, this gets a page too but the previous one this time.
Kind: instance method of MuPaginator
A mystical thing, uses traps to watch for changes to an object, also has derived properties.
Kind: global function
Example
let person = MuObservableObject(
{props: ['firstName','lastName'],
derived: {
fullName: {
deps: ['firstName','lastName'],
fn: function(){
return `${this.firstName} ${this.lastName}`
}
}
}})
let dude = new person({firstName: 'jim', lastName: 'smith'})
console.log(dude.fullName)
// Magically fullName is 'jim smith' and if you change first or last...magic
// fullName updates...crazy
person.on('change:fullName',doSomething)
// can also listen for changes on any property.
Factory function for MuView, uses currying to allow default options, calling result with final options to produce instances.
Kind: global function
Example
let personView = muView({template: '<div></div>'})
let personOne = personView({model: personOneModel })
let personTwo = personView({model: personTwoModel })
Inject a style sheet, if you feel so inclined
Kind: global function
Param | Type | Description |
---|---|---|
style | String |
some string of css |
id | String |
optional id for the style node you are about to inject |
Example
muCss('.someClass {background-color: red}')
A cheap, light weight jquery-ish knockoff
Kind: global function
Param | Type | Description |
---|---|---|
selector | String | DomNode |
If text it's a selector, or if the text looks like html, muDom will turn it into a fragment and treat it as the context, or if it is a DomNode of some kind, muDom will treat it as the context |
context | DomNode |
the context find and subsequent operations will be run under defaults to document |
Example
muDom('.foo')
// shorthand for
muDom(document).find('foo')
- muDom(selector, context)
- .html(newHtml)
- .value(value)
- .text(newTxt)
- .setAttribute(name, value)
- .src(src)
- .each(fn)
- .some(fn)
- .map(fn)
- .siblings()
- .focus()
- .element()
- .blur()
- .toggle(className)
- .hide()
- .show()
- .addClass(class)
- .removeClass(class)
- .swap(el)
- .on(event, handler, options)
- .off(event, handler, options)
- .find(selector)
- .append(node)
- .prepend(node)
- .remove()
- .clear()
Sets the innerHTML of matched elements. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
newHtml | the new html for matched elements. |
Sets the value of matched elements. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
value | the new value for matched elements. |
Sets the innerText of matched elements. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
newTxt | the new text for matched elements. |
Sets an attribute of matched elements. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
name | name of attribute to set |
value | value of attribute |
Helper: Sets 'src' of element. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
src | value of src attributed desired |
Calls fn for each matched element. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
fn | some function |
Determines if some element in matched elements passes fn. Not chainable. Basically Array.some()
Kind: static method of muDom
Param | Description |
---|---|
fn | some function |
Map over matched elements. Not chainable.
Kind: static method of muDom
Param | Description |
---|---|
fn | some function |
Get siblings. Chainable on siblings.
Kind: static method of muDom
Focus an element. Only works if this has one matching element. Chainable.
Kind: static method of muDom
Get ref to dom element (assumes there is only one match, returning first) obviously non-chainable
Kind: static method of muDom
Remove focus from matched elements, if one of them happens to have focus. Chainable.
Kind: static method of muDom
Toggles a class on matched elements. Defaults to '.muHide' which as its name suggests hides the element. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
className | class to toggle |
Hides matched elements. Chainable.
Kind: static method of muDom
Shows matched elements. Chainable.
Kind: static method of muDom
Adds a class to matched elements. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
class | class name to add |
Removes a class from matched elements. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
class | class name to add |
Swaps matched elements with new element. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
el | new element |
Listen to some event on matched elements. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
event | event to listen for |
handler | some fn |
options | options for addEventListener |
Removes some event listener from matched elements. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
event | event to listen for |
handler | some fn |
options | options for addEventListener |
Find some matching element/elements in current context. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
selector | some selector |
Append some element to matched elements. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
node | some dom node to append |
Prepend some element to matched elements. Chainable.
Kind: static method of muDom
Param | Description |
---|---|
node | some dom node to prepend |
Remove matched elements from their parents. Not chainable.
Kind: static method of muDom
Clear the contents of matched elements. Chainable.
Kind: static method of muDom
© 2016-2017 Seth Price