Skip to content
/ mu Public

A few frills reactive anti-framework for use in electron

Notifications You must be signed in to change notification settings

dotmilk/mu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mu

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


Classes

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

MuPageManagerMuEvent

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.

MuCollectionMuEvent

A collection emitting events on certain actions

MuPagedCollectionMuCollection

Uses MuPaginator to paginate a MuCollection, why would you want to do this? I dunno, you're the one using it.

MuCollectionViewMuWrapperView

Generic view wrapper for a collection

MuPaginatedCollectionViewMuCollectionView

View wrapper for a paginated collection

MuWrapperViewMuEvent

Abstract class for wrapping more complex constructs.

MuViewMuEvent

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

Functions

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

MuDialogue

Abstract dialogue class for use in MuDialogueManager

Kind: global class

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.

Kind: global class

new MuManager()

Make a manager object

muManager.add(name, opts)

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.

muManager.get(name)

Retrieve a thing you have stored

Kind: instance method of MuManager

Param Type Description
name String key to retrieve

MuPage

Abstract class for page controllers

Kind: global class

new MuPage(options)

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

muPage.onLoad()

Handler for load:pageName, subclass may implement

Kind: instance method of MuPage

muPage.onShow()

Handler for show:pageName, subclass may implement

Kind: instance method of MuPage

muPage.onHide()

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

new MuPageManager(options)

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

muPageManager.getAttributes(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.

muPageManager.getDOM(name)

Get a reference to the DOM node tied to specified page

Kind: instance method of MuPageManager

Param Type Description
name String Name of page

muPageManager.getController(name)

Get the controller instance bound to specified page

Kind: instance method of MuPageManager

Param Type Description
name String Name of page

muPageManager.load(name)

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

muPageManager.on(event, fn)

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

muPageManager.removeListener(event, fn)

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

muPageManager.clearListeners()

Clears all listeners

Kind: instance method of MuPageManager
Overrides: clearListeners

muPageManager.emit(event)

Emit event

Kind: instance method of MuPageManager
Overrides: emit

Param Type Description
event String Name of event to emit

MuState

Abstract State class for use in MuStateMachine

Kind: global class

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

new MuStateMachine(options)

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

muStateMachine.addState(name, stateDef)

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

muStateMachine.transition(name)

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.

muStateMachine.handle(name)

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

new MuCollection(options)

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

muCollection.addBulk(items)

Convenience function for add(stuff,true)

Kind: instance method of MuCollection

Param Type Description
items Array | SingleItem Stuff to add

muCollection.add(items, bulk)

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'

muCollection.sort(comparator, reverse)

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

muCollection.remove(idxs)

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

muCollection.get(id)

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

muCollection.each(fn)

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

muCollection.reset(items)

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

muCollection.on(event, fn)

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

muCollection.removeListener(event, fn)

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

muCollection.clearListeners()

Clears all listeners

Kind: instance method of MuCollection
Overrides: clearListeners

muCollection.emit(event)

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

new MuPagedCollection(options)

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

muPagedCollection.setPageSize(n)

Sets the number of items per 'page'

Kind: instance method of MuPagedCollection

Param Type Description
n Integer Number of items per page

muPagedCollection.getPageSize()

Gets the current page size

Kind: instance method of MuPagedCollection

muPagedCollection.maxPage()

Gets maximum possible page number with current collection

Kind: instance method of MuPagedCollection

muPagedCollection.currentPageNumber()

Gets the current page number

Kind: instance method of MuPagedCollection

muPagedCollection.currentPage()

Gets a reference to current page

Kind: instance method of MuPagedCollection

muPagedCollection.getPage(n)

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

muPagedCollection.nextPage()

Gets the next page

Kind: instance method of MuPagedCollection

muPagedCollection.previousPage()

Gets previous page

Kind: instance method of MuPagedCollection

muPagedCollection.lastPage()

Gets last page

Kind: instance method of MuPagedCollection

muPagedCollection.firstPage()

Gets first page

Kind: instance method of MuPagedCollection

muPagedCollection.addBulk(items)

Convenience function for add(stuff,true)

Kind: instance method of MuPagedCollection
Overrides: addBulk

Param Type Description
items Array | SingleItem Stuff to add

muPagedCollection.add(items, bulk)

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'

muPagedCollection.sort(comparator, reverse)

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

muPagedCollection.remove(idxs)

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

muPagedCollection.get(id)

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

muPagedCollection.each(fn)

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

muPagedCollection.reset(items)

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

muPagedCollection.on(event, fn)

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

muPagedCollection.removeListener(event, fn)

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

muPagedCollection.clearListeners()

Clears all listeners

Kind: instance method of MuPagedCollection
Overrides: clearListeners

muPagedCollection.emit(event)

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

muCollectionView.init()

Stub function, extending class may implement

Kind: instance method of MuCollectionView
Overrides: init

muCollectionView.render()

Stub function, extending class may implement

Kind: instance method of MuCollectionView
Overrides: render

muCollectionView.remove()

Stub function, extending class must implement

Kind: instance abstract method of MuCollectionView
Overrides: remove

muCollectionView.on(event, fn)

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

muCollectionView.removeListener(event, fn)

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

muCollectionView.clearListeners()

Clears all listeners

Kind: instance method of MuCollectionView
Overrides: clearListeners

muCollectionView.emit(event)

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

muPaginatedCollectionView.init()

Stub function, extending class may implement

Kind: instance method of MuPaginatedCollectionView
Overrides: init

muPaginatedCollectionView.render()

Stub function, extending class may implement

Kind: instance method of MuPaginatedCollectionView
Overrides: render

muPaginatedCollectionView.remove()

Stub function, extending class must implement

Kind: instance abstract method of MuPaginatedCollectionView
Overrides: remove

muPaginatedCollectionView.on(event, fn)

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

muPaginatedCollectionView.removeListener(event, fn)

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

muPaginatedCollectionView.clearListeners()

Clears all listeners

Kind: instance method of MuPaginatedCollectionView
Overrides: clearListeners

muPaginatedCollectionView.emit(event)

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

new MuWrapperView(options)

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

muWrapperView.init()

Stub function, extending class may implement

Kind: instance method of MuWrapperView

muWrapperView.render()

Stub function, extending class may implement

Kind: instance method of MuWrapperView

muWrapperView.remove()

Stub function, extending class must implement

Kind: instance abstract method of MuWrapperView

muWrapperView.on(event, fn)

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

muWrapperView.removeListener(event, fn)

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

muWrapperView.clearListeners()

Clears all listeners

Kind: instance method of MuWrapperView
Overrides: clearListeners

muWrapperView.emit(event)

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

new MuView(options)

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

muView.references(references)

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')})

muView.parseBindings(bindings)

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

muView.bindings(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

muView.events()

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

muView.addCollection(options)

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'})

muView.registerSubview(view)

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

muView.renderSubviews()

Attempts to call render on all subviews

Kind: instance method of MuView

muView.remove()

Attempts to remove first all subviews and then self from the dom

Kind: instance method of MuView

muView.render()

Slaps events and model bindings onto this.el and then renders subviews

Kind: instance method of MuView

muView.on(event, fn)

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

muView.removeListener(event, fn)

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

muView.clearListeners()

Clears all listeners

Kind: instance method of MuView
Overrides: clearListeners

muView.emit(event)

Emit event

Kind: instance method of MuView
Overrides: emit

Param Type Description
event String Name of event to emit

MuTagen

Programmatically create some html fragment template

Kind: global class

new MuTagen()

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()

muTagen.tag(name, prefix)

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>

muTagen.attribute(name, prop)

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')

muTagen.class(prop)

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'

muTagen.id(prop)

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'

muTagen.text(prop)

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'

muTagen.close()

Close this tag level

Kind: instance method of MuTagen

muTagen.closeAll()

Go all the way back to the first tag that was opened

Kind: instance method of MuTagen

muTagen.compile()

Now you are done adding tags and attributes etc

Kind: instance method of MuTagen

muTagen.render(props)

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

MuBroker

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

new MuBroker(config)

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)})

muBroker.subscribe(name, receiver, type)

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

muBroker.unsubscribe(name, receiver)

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

muBroker.publish(name, msg, type) ⇒ Promise

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

MuEvent

Very simple no frills Event Emitter so to speak, might add emitter.once later

Kind: global class

new MuEvent()

Takes no arguments

Example

let emitter = new MuEvent()
emitter.on('whatever',()=>{console.log(whatever)})
emitter.emit('whatever')

muEvent.on(event, fn)

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

muEvent.removeListener(event, fn)

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

muEvent.clearListeners()

Clears all listeners

Kind: instance method of MuEvent

muEvent.emit(event)

Emit event

Kind: instance method of MuEvent

Param Type Description
event String Name of event to emit

MuNodeManager

Name, store and possibly clone / possibly remove arbitrary nodes of your document for later retrieval. Pretty fancy right?

Kind: global class

new MuNodeManager()

Nothing to see here, pretty standard instance constructor...

muNodeManager.add(name, selector, context, clone)

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

muNodeManager.addAndRemove()

Like add but it removes the node from the document after jacking it

Kind: instance method of MuNodeManager

muNodeManager.getCloned()

Get a clone of something you stored earlier!!

Kind: instance method of MuNodeManager

muNodeManager.get()

Get a direct reference to something you stored earlier! Not as exciting as getCloned so only one !

Kind: instance method of MuNodeManager

muNodeManager.getCurried(name, cloned)

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...

MuPaginator

Class for 'paginating' an array

Kind: global class

new MuPaginator(options)

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]

muPaginator.paginator()

Internal generator function, for the actual paginating, cause why the hell not

Kind: instance method of MuPaginator

muPaginator.getPage(pageNumber)

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

muPaginator.maxPage()

Returns the max possible page number

Kind: instance method of MuPaginator

muPaginator.isLastPage()

Are we on the last page?

Kind: instance method of MuPaginator

muPaginator.lastPage()

If we weren't, we are now, on the last page that is.

Kind: instance method of MuPaginator

muPaginator.firstPage()

Similar to lastPage except by some miracle, gets you the first page

Kind: instance method of MuPaginator

muPaginator.nextPage()

Now this one is unique, it gets you the next page

Kind: instance method of MuPaginator

muPaginator.previousPage()

Ok I lied nextPage wasn't that unique, this gets a page too but the previous one this time.

Kind: instance method of MuPaginator

MuObservableObject()

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.

muView()

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 })

muCss(style, id)

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}')

muDom(selector, context)

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.html(newHtml)

Sets the innerHTML of matched elements. Chainable.

Kind: static method of muDom

Param Description
newHtml the new html for matched elements.

muDom.value(value)

Sets the value of matched elements. Chainable.

Kind: static method of muDom

Param Description
value the new value for matched elements.

muDom.text(newTxt)

Sets the innerText of matched elements. Chainable.

Kind: static method of muDom

Param Description
newTxt the new text for matched elements.

muDom.setAttribute(name, value)

Sets an attribute of matched elements. Chainable.

Kind: static method of muDom

Param Description
name name of attribute to set
value value of attribute

muDom.src(src)

Helper: Sets 'src' of element. Chainable.

Kind: static method of muDom

Param Description
src value of src attributed desired

muDom.each(fn)

Calls fn for each matched element. Chainable.

Kind: static method of muDom

Param Description
fn some function

muDom.some(fn)

Determines if some element in matched elements passes fn. Not chainable. Basically Array.some()

Kind: static method of muDom

Param Description
fn some function

muDom.map(fn)

Map over matched elements. Not chainable.

Kind: static method of muDom

Param Description
fn some function

muDom.siblings()

Get siblings. Chainable on siblings.

Kind: static method of muDom

muDom.focus()

Focus an element. Only works if this has one matching element. Chainable.

Kind: static method of muDom

muDom.element()

Get ref to dom element (assumes there is only one match, returning first) obviously non-chainable

Kind: static method of muDom

muDom.blur()

Remove focus from matched elements, if one of them happens to have focus. Chainable.

Kind: static method of muDom

muDom.toggle(className)

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

muDom.hide()

Hides matched elements. Chainable.

Kind: static method of muDom

muDom.show()

Shows matched elements. Chainable.

Kind: static method of muDom

muDom.addClass(class)

Adds a class to matched elements. Chainable.

Kind: static method of muDom

Param Description
class class name to add

muDom.removeClass(class)

Removes a class from matched elements. Chainable.

Kind: static method of muDom

Param Description
class class name to add

muDom.swap(el)

Swaps matched elements with new element. Chainable.

Kind: static method of muDom

Param Description
el new element

muDom.on(event, handler, options)

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

muDom.off(event, handler, options)

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

muDom.find(selector)

Find some matching element/elements in current context. Chainable.

Kind: static method of muDom

Param Description
selector some selector

muDom.append(node)

Append some element to matched elements. Chainable.

Kind: static method of muDom

Param Description
node some dom node to append

muDom.prepend(node)

Prepend some element to matched elements. Chainable.

Kind: static method of muDom

Param Description
node some dom node to prepend

muDom.remove()

Remove matched elements from their parents. Not chainable.

Kind: static method of muDom

muDom.clear()

Clear the contents of matched elements. Chainable.

Kind: static method of muDom


© 2016-2017 Seth Price

About

A few frills reactive anti-framework for use in electron

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages