Giter Site home page Giter Site logo

mount.js's Introduction

Mount 2.0

Rewritten from scratch to improve and simplify the API and behavior of mounted objects.

Mount.js

Mount is a utility function to make working with values chainable and more Functional in style.

Mount will turn any inputs into a store object who's properties are accessor methods, that accept callbacks.

Each callback will be passed a standard set of arugments.

  • Value: the value of the prop of the original input.
  • Store: the mountStore which holds all the values, and their Accessor Functions.
  • Mount: a helper function to add additional values to the mountStore.
  • Prop: the prop by which one can access the value in the Store.
  • Input: the original source input, as it was passed in when mounted.

Accessor Functions will return whatever your callback explicitly returns, or the instance of mountStore.fx if undefined is returned.

##Examples:

/** ======================================
   Mounting Primatives
======================================= **/

// Strings
  var s = 'john doe';
      m = mount( s, 'name')
           .name(function( name, store, mount, prop, input ){
              mount(32, 'age'), console.log( 'Welcome back ' + name );
            })
            .age(function(age){
              console.log(age)
            });
    
/** ======================================
   Mounting Objects
======================================= **/

  var o = { name: "john doe", age: 22 },
      m = mount(o)
            .name(function( name, store, mount, prop, input ){
               console.log('the user\'s name is ' + name + ' and he is ' + store.age + ' years old' );
            }); 

/** ======================================
   Mounting Arrays
======================================= **/

  var a = ['john doe', 22 ];
      m = mount(a)[0](function( name, store, mount, prop, input ){
            console.log('Welcome back ' + name);
          })

// mapTo
      
  var a = ['john doe', 22 ];
      m = mount(a)
            .mapTo({name: 0, age: 1})
            .name(function(name, person){ console.log( 'hello ' + name + ', your age is ' + person.age )})

/** ======================================
   Remounting Mounted Stores
======================================= **/

  var o = { name: "john doe", age: 22 };
  var r = mount(o).name((name, person ) => { person.name = name.toUpperCase() } );
  var s = mount(r).name(function(name){ return name }); // explicit return value "JOHN DOE" returned

      console.log(s) // "JOHN DOE"


/** 
      Helper Functions
*/

// .has() checks for the presence of a property, and conditionaly calls one of two optional callbacks.
// .hasNot() checks for the absence of a property, and conditionaly calls one of two optional callbacks.


var o = {},
    m = mount(o).has('name', null, function(n,s,m) { m('John Doe', 'Name'); return s; });
    m = mount(o).hasNot('age', function(){ console.log('not found!')}); 

mount.js's People

Contributors

rexfordkelly avatar

Watchers

 avatar

Forkers

aarboleda1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.