Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alt

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alt - npm Package Compare versions

Comparing version 0.13.11 to 0.13.13

57

CHANGELOG.md
# Changelog
## 0.14.1
Dependency Update:
* es-symbol has been updated to 1.1.1
## 0.14.0
Changed:
* createStore no longer throws when it encounters a store with the same name. Instead if generates a new name for you and warns you in the console. If a store name is not specified due to using anonymous functions then a warning is also logged.
Other:
* Includes many README tweaks.
Dependency Update:
* es-symbol has been updated to 1.1.0 for better IE8 compatibility.
## 0.13.11
New:
* Added access to the internal EventEmitter used by the store. This can be access on the store instance by using `getEventEmitter()` and can be used for custom events.
* Added a setState method for syntactic sugar which sets the state in the instance variables inside your store and then emits a change event.
* Added emitChange method. No more `this.getInstance().emitChange`, now you can just `this.emitChange()` from inside a store.
* Added syntactic sugar for waitFor. `waitFor` now takes in a splat or array of stores or dispatch tokens.
* The `alt` instance now gets passed to the store constructor as well as the actions constructor.
* ActionListener is a util that allows you to listen in on specific actions. Now it's even more lightweight if you want to listen in on a specific action but don't want the weight of a store. This comes as a util meaning it doesn't increase the size of core alt. Use it if you need it.
Fixed:
* addStore now has the `saveStore` parameter as well.
## 0.13.10

@@ -9,2 +44,3 @@

* FinalStore is a util Store that emits a change once all other stores have emitted. [commit](https://github.com/goatslacker/alt/commit/c104fb73eedd61f4c1dbd4ac074ce8a2f4b818bf)
* Added a `saveStore` parameter to `alt.createStore`. This parameter controls whether we should save the store internally (for snapshots, bootstraps) or not. Default is true.

@@ -34,10 +70,2 @@ Fixed:

Removed:
* Remove `ReactStoreMixin`. [commit](https://github.com/goatslacker/alt/commit/fb1823c900a61fa5a99dffc4ce1a2be17f8d1717)
Refactored:
* Utilize ES6 import. [commit](https://github.com/goatslacker/alt/commit/ffc66dd99447b42b7ac08f7282f41d7d495ed547)
## 0.13.4

@@ -59,3 +87,3 @@

Dependency Updates:
Dev Dependency Updates:

@@ -99,7 +127,10 @@ * Upgrade to Babel 4.0 (formerly 6to5). [commit](https://github.com/goatslacker/alt/commit/b7dd7795fb8e5b727f07ca578ca1fc930ed6c18b)

Dependency Updates:
Dependency update:
* Update 6to5. [commit](https://github.com/goatslacker/alt/commit/5facbbbc8d5fb8573e7edcf5b0dd76b20b37de32)
* Update es-symbol [commit](https://github.com/goatslacker/alt/commit/d2a1377357eff68c8512be2971228ab863751cba)
Dev Dependency Updates:
* Update 6to5. [commit](https://github.com/goatslacker/alt/commit/5facbbbc8d5fb8573e7edcf5b0dd76b20b37de32)
## 0.10.2

@@ -123,6 +154,2 @@

Refactored:
* Utilize ES6 `let`. [commit](https://github.com/goatslacker/alt/commit/6062ad9261be79ed471abfccfe237bda4fb58c7f)
## 0.9.0

@@ -129,0 +156,0 @@

@@ -289,6 +289,19 @@ "use strict";

var storeInstance = undefined;
var key = iden || StoreModel.displayName || StoreModel.name;
var key = iden || StoreModel.name || StoreModel.displayName || "";
if (saveStore && this.stores[key]) {
throw new ReferenceError("A store named " + key + " already exists, double check your store names or pass in\nyour own custom identifier for each store");
if (saveStore && (this.stores[key] || !key)) {
/* istanbul ignore else */
if (typeof console !== "undefined") {
if (this.stores[key]) {
console.warn(new ReferenceError("A store named " + key + " already exists, double check your store " + "names or pass in your own custom identifier for each store"));
} else {
console.warn(new ReferenceError("Store name was not specified"));
}
}
// guarantee the store has a unique key name
var count = 0;
while (this.stores[key]) {
key = key + String(++count);
}
}

@@ -368,3 +381,3 @@

var actions = assign({}, getInternalMethods(ActionsClass.prototype, builtInProto));
var key = ActionsClass.displayName || ActionsClass.name;
var key = ActionsClass.name || ActionsClass.displayName || "";

@@ -371,0 +384,0 @@ var ActionsGenerator = (function (ActionsClass) {

@@ -303,6 +303,19 @@ "use strict";

var storeInstance = undefined;
var key = iden || StoreModel.displayName || StoreModel.name;
var key = iden || StoreModel.name || StoreModel.displayName || "";
if (saveStore && this.stores[key]) {
throw new ReferenceError("A store named " + key + " already exists, double check your store names or pass in\nyour own custom identifier for each store");
if (saveStore && (this.stores[key] || !key)) {
/* istanbul ignore else */
if (typeof console !== "undefined") {
if (this.stores[key]) {
console.warn(new ReferenceError("A store named " + key + " already exists, double check your store " + "names or pass in your own custom identifier for each store"));
} else {
console.warn(new ReferenceError("Store name was not specified"));
}
}
// guarantee the store has a unique key name
var count = 0;
while (this.stores[key]) {
key = key + String(++count);
}
}

@@ -383,3 +396,3 @@

var actions = assign({}, getInternalMethods(ActionsClass.prototype, builtInProto));
var key = ActionsClass.displayName || ActionsClass.name;
var key = ActionsClass.name || ActionsClass.displayName || "";

@@ -386,0 +399,0 @@ var ActionsGenerator = (function (ActionsClass) {

@@ -20,3 +20,3 @@ ---

The constructor of your store definition receieves the alt instance as its first and only argument.
The constructor of your store definition receieves the alt instance as its first and only argument. All instance variables, values assigned to `this`, in any part of the StoreModel will become part of state.

@@ -23,0 +23,0 @@ ## StoreModel#on

@@ -16,3 +16,3 @@ ---

The bread and butter method of your store. This method is used to get your state out of the store. Once it is called it performs a shallow copy of your store's state, this is so you don't accidentally overwrite/mutate any of your store's state.
The bread and butter method of your store. This method is used to get your state out of the store. Once it is called it performs a shallow copy of your store's state, this is so you don't accidentally overwrite/mutate any of your store's state. The state is pulled from the [StoreModel](createStore.md)'s instance variables.

@@ -19,0 +19,0 @@ ```js

{
"name": "alt",
"version": "0.13.11",
"version": "0.13.13",
"description": "A flux implementation",
"main": "dist/alt.js",
"dependencies": {
"es-symbol": "^1.0.1",
"es-symbol": "^1.1.1",
"eventemitter3": "^0.1.6",

@@ -9,0 +9,0 @@ "flux": "^2.0.1",

@@ -174,3 +174,3 @@ # alt

// as well as for many actions
this.generateActions('updateCity', 'updateState', 'updateCountry')
this.generateActions('updateCity', 'updateCountry')
}

@@ -186,3 +186,2 @@ }

locationActions.updateCity('Las Vegas')
locationActions.updateState('Nevada')
locationActions.updateCountry('US')

@@ -222,3 +221,3 @@ ```

```js
var locationActions = alt.generateActions('updateLocation', 'updateCity', 'updateState', 'updateCountry')
var locationActions = alt.generateActions('updateLocation', 'updateCity', 'updateCountry')
```

@@ -238,9 +237,9 @@

this.city = 'Denver'
this.state = 'Colorado'
this.country = 'US'
}
onUpdateLocation(obj) {
var { city, state } = obj
var { city, country } = obj
this.city = city
this.state = state
this.country = country
}

@@ -254,2 +253,4 @@ }

All values assigned to `this` inside the store will accessible via `LocationStore.getState()`.
#### createStore API

@@ -313,3 +314,3 @@

this.city = 'Portland'
this.state = 'Oregon'
this.country = 'US'
}

@@ -336,6 +337,6 @@

constructor() {
this.bindAction(locationActions.UPDATE_STATE, this.onUpdateState)
this.bindAction(locationActions.UPDATE_CITY, this.onUpdateCity)
this.city = ''
this.state = ''
this.country = ''
}

@@ -357,3 +358,3 @@ }

constructor() {
this.generateActions('updateCity', 'updateState')
this.generateActions('updateCity', 'updateCountry')
}

@@ -373,3 +374,3 @@ }

this.city = 'Austin'
this.state = 'Texas'
this.country = 'US'
}

@@ -381,4 +382,4 @@

onUpdateState(state) {
this.state = state
onUpdateCountry(country) {
this.country = country
}

@@ -390,4 +391,25 @@ }

Actions who have a `onCamelCasedAction` method or an `actionName` method available in the store will be bound.
Actions who have a `onCamelCasedAction` method or an `actionName` method available in the store will be bound. In this example `locationActions.updateCity` will be handled by `onUpdateCity`. There is no difference between calling the action handler `updateCity` or `onUpdateCity` it's just a matter of aesthetic preference.
A better approach is to specify which action handlers belong to which actions this way you have ultimate control over what gets called and handled. The function `bindListeners` is the inverse of `bindActions`. `bindListeners` takes an object of action handlers as keys and actions as a value.
```js
class LocationStore {
constructor() {
this.bindListeners({
handleCity: locationActions.updateCity,
handleCountry: [locationActions.updateCountry, locationActions.updateLatLng]
});
}
handleCity(data) {
// will only be called by locationActions.updateCity()
}
handleCountry(data) {
// will be called by locationActions.updateCountry() and locationActions.updateLatLng()
}
}
```
#### Methods available in Stores

@@ -468,3 +490,3 @@

<p>
State {this.state.state}
Country {this.state.country}
</p>

@@ -504,3 +526,3 @@ </div>

<p>
State {this.state.state}
Country {this.state.country}
</p>

@@ -507,0 +529,0 @@ </div>

@@ -263,2 +263,3 @@ import Alt from '../dist/alt-with-runtime'

const consoleWarn = console.warn.bind(console)

@@ -272,2 +273,3 @@ /* istanbul ignore next */

alt2.recycle()
console.warn = consoleWarn
},

@@ -631,29 +633,47 @@

'stores with colliding names'() {
try {
let MyStore = (function () {
return function MyStore() { }
}())
alt.createStore(MyStore)
assert.equal(true, false, 'I was able to create a store with the same name')
} catch (e) {
if (e.name === 'AssertionError') {
throw e
}
assert.equal(e instanceof ReferenceError, true, 'error was thrown for store with same name')
let called = false
console.warn = function (x) {
called = true
assert.equal(x instanceof ReferenceError, true)
}
try {
let mystore = (function () {
return function mystore() { }
}())
alt.createStore(mystore, 'MyStore')
assert.equal(true, false, 'I was able to create a store with the same name by passing in an identifier')
} catch (e) {
if (e.name === 'AssertionError') {
throw e
}
assert.equal(e instanceof ReferenceError, true, 'error was thrown for store with same name')
let MyStore = (function () {
return function MyStore() { }
}())
alt.createStore(MyStore)
assert.equal(called, true, 'a warning was called')
assert.equal(typeof alt.stores.MyStore1, 'object', 'a store was still created')
},
'colliding names via identifier'() {
let called = false
console.warn = function (x) {
called = true
assert.equal(x instanceof ReferenceError, true)
}
class auniquestore { }
alt.createStore(auniquestore, 'MyStore')
assert.equal(called, true, 'a warning was called')
assert.equal(typeof alt.stores.MyStore1, 'object', 'a store was still created')
},
'not providing a store name via anonymous function'() {
let called = false
console.warn = function (x) {
called = true
assert.equal(x instanceof ReferenceError, true)
}
alt.createStore(function () { })
assert.equal(called, true, 'a warning was called')
assert.equal(typeof alt.stores[''], 'object', 'a store with no name was still created')
},
'multiple deferrals'(done) {

@@ -1172,4 +1192,12 @@ myActions.moreActions()

},
'actions with no name are still ok'() {
var actions = alt.createActions(function () {
this.generateActions('foo')
})
assert.equal(typeof actions.foo, 'function', 'action still exists')
},
}
export default tests
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc