Skip to content

Commit

Permalink
Resolve 2.0 merge conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericelliott committed May 31, 2015
2 parents f21ea73 + 4ff3dc6 commit 9b19ead
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 1 deletion.
60 changes: 59 additions & 1 deletion README.md
Expand Up @@ -194,6 +194,22 @@ var myBar = bar({name: 'Moe\'s'});
myBar.add({name: 'Homer' }).open().getMember('Homer');
```

## Statics

Stamps have a `static` method. This method applies passed object properties to the calling stamp's object. `static` is a convenience method. The old school way to apply statics to a stamp is by using stampit's `mixIn/extend` method.

```js
stampit.extend(stamp, {
foo: 'foo'
});

This can now be written as:

stamp.static({
foo: 'foo'
});
```

## More chaining

Chaining stamps *always* creates new stamps.
Expand Down Expand Up @@ -230,6 +246,7 @@ myStamp = myStamp.refs({
});
```

<<<<<<< HEAD
And `.props()` ...

```js
Expand All @@ -241,6 +258,21 @@ myStamp = myStamp.props({
```

And `.init()` ...
=======
And `.static()` ...

```js
myStamp.static({
foo: {bar: 'bar'},
staticOverride: false
}).static({
bar: 'bar',
staticOverride: true
});
```

And `.enclose()` ...
>>>>>>> master
```js
myStamp = myStamp.init(function () {
Expand Down Expand Up @@ -274,7 +306,11 @@ And `.compose()`.
var newStamp = baseStamp.compose(myStamp);
```

<<<<<<< HEAD
## Pass multiple objects into .methods(), .refs(), .init(), props(), or .compose().
=======
## Pass multiple objects into .methods(), .state(), .enclose(), .static(), or .compose().
>>>>>>> master
Stampit mimics the behavior of `_.extend()`, `$.extend()` when you pass multiple objects into one of the stamp methods.
In other words, it will copy all of the properties from those objects to the `.methods`, `.refs`, `.init` or `.props` of the stamp.
Expand Down Expand Up @@ -334,6 +370,7 @@ Or even `.compose()` ...
### stampit() ###

Return a factory function (called a stamp) that will produce new objects using the
<<<<<<< HEAD
components that are passed in or composed.

* @param {Object} [options] Options to build stamp from: `{ methods, refs, init, props }`
Expand All @@ -348,6 +385,21 @@ components that are passed in or composed.
* @return {Function} factory.refs Add references to the stamp. Chainable.
* @return {Function} factory.init Add a closure which called on object instantiation. Chainable.
* @return {Function} factory.props Add deeply cloned properties to the produced objects. Chainable.
=======
prototypes that are passed in or composed.

* `@param {Object} [methods]` A map of method names and bodies for delegation.
* `@param {Object} [state]` A map of property names and values to clone for each new object.
* `@param {Function} [enclose]` A closure (function) used to create private data and privileged methods.
* `@return {Function} stamp` A factory to produce objects using the given prototypes.
* `@return {Function} stamp.create` Chaining sugar that invokes the stamp.
* `@return {Object} stamp.fixed` An object map containing the fixed prototypes.
* `@return {Function} stamp.methods` Add methods to the methods prototype. Chainable.
* `@return {Function} stamp.state` Add properties to the state prototype. Chainable.
* `@return {Function} stamp.enclose` Add or replace the closure prototype. Chainable.
* `@return {Function} stamp.compose` Add stamp to stamp. Chainable.
* `@return {Function} stamp.static` Add properties to the factory object. Chainable.
>>>>>>> master

## The stamp object ##
Expand Down Expand Up @@ -438,6 +490,12 @@ arguments. Taking arguments with an `.init()` function is an
anti-pattern that should be avoided, when possible.


### stamp.static() ###

Take n objects and add all props to the factory object.
* @return {Object} stamp The factory in question (`this`).


## Utility methods ##

### stampit.methods() ###
Expand Down Expand Up @@ -501,7 +559,7 @@ the resulting stamp with other stamps willy-nilly, because if two
different stamps depend on the argument passing feature, the arguments
will probably clash with each other, producing very unexpected results.

* @param {Function} Constructor
* @param {Function} Constructor
* @return {Function} A composable stampit factory (aka stamp).

```js
Expand Down
4 changes: 4 additions & 0 deletions package.json
@@ -1,6 +1,10 @@
{
"name": "stampit",
<<<<<<< HEAD
"version": "2.0.0",
=======
"version": "1.2.0",
>>>>>>> master
"description": "Create objects from reusable, composable behaviors.",
"author": {
"name": "Eric Elliott",
Expand Down
64 changes: 64 additions & 0 deletions stampit.js
Expand Up @@ -17,7 +17,20 @@ var isObject = require('lodash/lang/isObject');
var create = Object.create;
var slice = require('lodash/array/slice');

<<<<<<< HEAD
var mixer = require('./mixer');
=======
/*jshint -W024 */

// Avoiding JSHist W003 violations.
var create, extractFunctions, stampit, compose, isStamp, convertConstructor;

create = function (o) {
if (arguments.length > 1) {
throw new Error('Object.create implementation only accepts the first parameter.');
}
function F() {}
>>>>>>> master

// Avoiding JSHist W003 violations.
var stampit;
Expand Down Expand Up @@ -111,6 +124,7 @@ function compose(factories) {
* @return {Function} factory.props Add deeply cloned properties to the produced objects. Chainable.
* @return {Function} factory.compose Combine several stamps into single. Chainable.
*/
<<<<<<< HEAD
stampit = function stampit(options) {
var fixed = {methods: {}, refs: {}, init: [], props: {}, static: {}};
fixed.state = fixed.refs; // Backward compatibility. 'state' is the old name for 'refs'.
Expand All @@ -122,6 +136,15 @@ stampit = function stampit(options) {
addProps(fixed, options.props);
addStatic(fixed, options.static);
}
=======
stampit = function stampit(methods, state, enclose) {
var fixed = {
methods: methods || {},
state: state,
enclose: extractFunctions(enclose),
static: {}
},
>>>>>>> master

var factory = function Factory(properties, args) {
properties = properties ? mixer.merge({}, fixed.props, properties) : deepClone(fixed.props);
Expand Down Expand Up @@ -198,6 +221,17 @@ stampit = function stampit(options) {
return mixer.mixin(newStamp, newStamp.fixed.static);
},

/**
* Take n objects and add all props to the factory object.
* @return {Object} stamp The factory in question (`this`).
*/
static: function stampStatic() {
var obj = fixed.static || {},
args = [obj].concat(slice.call(arguments));
fixed.static = mixInChain.apply(this, args);

return mixIn(this, fixed.static);
},
/**
* Take one or more factories produced from stampit() and
* combine them with `this` to produce and return a new factory.
Expand Down Expand Up @@ -228,6 +262,7 @@ function isStamp(obj) {
);
}

<<<<<<< HEAD
function convertConstructor(Constructor) {
var stamp = stampit();
mixer.mixinChainFunctions(stamp.fixed.methods, Constructor.prototype);
Expand All @@ -244,6 +279,35 @@ function shortcutMethod(extensionFunction, args) {
extensionFunction(stamp.fixed, args);
return stamp;
}
=======
if (source.fixed.enclose) {
f.enclose = f.enclose.concat(source.fixed.enclose);
}

if (source.fixed.static) {
f.static = mixIn(f.static, source.fixed.static);
}
}
});
return mixIn(result, f.static);
};

/**
* Check if an object is a stamp.
* @param {Object} obj An object to check.
* @returns {Boolean}
*/
isStamp = function isStamp(obj) {
return (
typeof obj === 'function' &&
typeof obj.fixed === 'object' &&
typeof obj.methods === 'function' &&
typeof obj.state === 'function' &&
typeof obj.enclose === 'function' &&
typeof obj.static === 'function'
);
};
>>>>>>> master

module.exports = mixer.mixin(stampit, {

Expand Down

0 comments on commit 9b19ead

Please sign in to comment.