1.0.0 • Published 9 years ago

null-object v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

null-object

a Null Object is an object with defined neutral ("null") behavior. The Null Object design pattern describes the uses of such objects and their behavior (or lack thereof)

wiki for null object pattern;

Example

import nullObject from 'nullObject';

function UserFactory() {
let User = {
  sendEmail() {
    someEmailClient.send('Wellcome');
  }
};

let UserNull = nullObject(User);

if(session.isLogged()) {
  return User;
}

return UserNull;
}

let CurrentUser = UserFactory();
CurrentUser.sendEmail();

You shouldn't care if user is logged, just send messages for the object.

API

/**

  • @param {Object} object to be applied
  • @param {Object} options
  • @param {Boolean} options.ownProps only if Object.hasOwnProperty
  • @default options.ownProps false
  • @example
  • nullObject({ sendEmail() {/ ... /}, {ownProps: false}); */