Skip to content

Commit

Permalink
Pass the alt instance to the constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Mar 5, 2015
1 parent 4f31eac commit f42b43a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
12 changes: 6 additions & 6 deletions dist/alt-with-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,12 @@ var Alt = (function () {
// so we can inherit any extensions from the provided store.

var Store = (function (StoreModel) {
function Store() {
function Store(alt) {
babelHelpers.classCallCheck(this, Store);

this[LIFECYCLE] = {};
this[LISTENERS] = {};
babelHelpers.get(Object.getPrototypeOf(Store.prototype), "constructor", this).call(this);
babelHelpers.get(Object.getPrototypeOf(Store.prototype), "constructor", this).call(this, alt);
}

babelHelpers.inherits(Store, StoreModel);
Expand All @@ -308,7 +308,7 @@ var Alt = (function () {
}
});

var store = new Store();
var store = new Store(this);

storeInstance = assign(new AltStore(this.dispatcher, store), getInternalMethods(StoreModel, builtIns));

Expand Down Expand Up @@ -347,10 +347,10 @@ var Alt = (function () {
var key = ActionsClass.displayName || ActionsClass.name;

var ActionsGenerator = (function (ActionsClass) {
function ActionsGenerator() {
function ActionsGenerator(alt) {
babelHelpers.classCallCheck(this, ActionsGenerator);

babelHelpers.get(Object.getPrototypeOf(ActionsGenerator.prototype), "constructor", this).call(this);
babelHelpers.get(Object.getPrototypeOf(ActionsGenerator.prototype), "constructor", this).call(this, alt);
}

babelHelpers.inherits(ActionsGenerator, ActionsClass);
Expand Down Expand Up @@ -379,7 +379,7 @@ var Alt = (function () {
return ActionsGenerator;
})(ActionsClass);

new ActionsGenerator();
new ActionsGenerator(this);

return Object.keys(actions).reduce(function (obj, action) {
var constant = formatAsConstant(action);
Expand Down
12 changes: 6 additions & 6 deletions dist/alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ var Alt = (function () {
// so we can inherit any extensions from the provided store.

var Store = (function (StoreModel) {
function Store() {
function Store(alt) {
_classCallCheck(this, Store);

this[LIFECYCLE] = {};
this[LISTENERS] = {};
_get(Object.getPrototypeOf(Store.prototype), "constructor", this).call(this);
_get(Object.getPrototypeOf(Store.prototype), "constructor", this).call(this, alt);
}

_inherits(Store, StoreModel);
Expand All @@ -323,7 +323,7 @@ var Alt = (function () {
}
});

var store = new Store();
var store = new Store(this);

storeInstance = assign(new AltStore(this.dispatcher, store), getInternalMethods(StoreModel, builtIns));

Expand Down Expand Up @@ -362,10 +362,10 @@ var Alt = (function () {
var key = ActionsClass.displayName || ActionsClass.name;

var ActionsGenerator = (function (ActionsClass) {
function ActionsGenerator() {
function ActionsGenerator(alt) {
_classCallCheck(this, ActionsGenerator);

_get(Object.getPrototypeOf(ActionsGenerator.prototype), "constructor", this).call(this);
_get(Object.getPrototypeOf(ActionsGenerator.prototype), "constructor", this).call(this, alt);
}

_inherits(ActionsGenerator, ActionsClass);
Expand Down Expand Up @@ -396,7 +396,7 @@ var Alt = (function () {
return ActionsGenerator;
})(ActionsClass);

new ActionsGenerator();
new ActionsGenerator(this);

return Object.keys(actions).reduce(function (obj, action) {
var constant = formatAsConstant(action);
Expand Down
12 changes: 6 additions & 6 deletions src/alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ your own custom identifier for each store`
// prototype with the mixin behaviour and I'm extending from StoreModel
// so we can inherit any extensions from the provided store.
class Store extends StoreModel {
constructor() {
constructor(alt) {
this[LIFECYCLE] = {}
this[LISTENERS] = {}
super()
super(alt)
}
}

Expand All @@ -266,7 +266,7 @@ your own custom identifier for each store`
getInstance: () => storeInstance
})

const store = new Store()
const store = new Store(this)

storeInstance = assign(
new AltStore(this.dispatcher, store),
Expand Down Expand Up @@ -295,8 +295,8 @@ your own custom identifier for each store`
const key = ActionsClass.displayName || ActionsClass.name

class ActionsGenerator extends ActionsClass {
constructor() {
super()
constructor(alt) {
super(alt)
}

generateActions(...actionNames) {
Expand All @@ -309,7 +309,7 @@ your own custom identifier for each store`
}
}

new ActionsGenerator()
new ActionsGenerator(this)

return Object.keys(actions).reduce((obj, action) => {
const constant = formatAsConstant(action)
Expand Down
26 changes: 26 additions & 0 deletions test/stores-get-alt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import assert from 'assert'
import Alt from '../dist/alt-with-runtime'

let alt = new Alt()

export default {
'the stores get the alt instance'() {
class MyStore {
constructor(alt) {
assert.equal(alt instanceof Alt, true, 'alt is an instance of Alt')
}
}

alt.createStore(MyStore)
},

'the actions get the alt instance'() {
class MyActions {
constructor(alt) {
assert.equal(alt instanceof Alt, true, 'alt is an instance of Alt')
}
}

alt.createActions(MyActions)
}
}

0 comments on commit f42b43a

Please sign in to comment.