Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #11 from XbyOrange/v2.0.0
Browse files Browse the repository at this point in the history
V1.2.0
  • Loading branch information
javierbrea committed Oct 16, 2019
2 parents a257c8d + 403963f commit a24de51
Show file tree
Hide file tree
Showing 8 changed files with 3,068 additions and 4,609 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"parser": "flow"
}
],
"no-undef": "error",
"no-unused-vars": ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }]
},
"extends": ["prettier"],
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Removed
### BREAKING CHANGES

## [TO BE DEPRECATED]
- "queriesDefaultValue" option has to be removed.
- Options should be accepted only as second argument. "uuid" should be defined only using the "uuid" option, not as second argument.

## [1.2.0] - 2019-10-16
### Added
- Add "queriesDefaultValue" option. If defined, queried instances will have default value corresponding to the value of query "key" in the default value object. If not, the behavior of "default value" will be the same than in previous versions, and will return the full object even for queried instances)
- Add "uuid" and "tags" options.
- Accept options object as second argument. (And still accepts "id" as second argument, and options as third argument in order to maintain retro-compatibility)

### Changed
- Emit "clean" event over root instance when an "update" is executed on any queried instance. (Full object is modified too).
- Upgrade mercury version and define it as peer dependency.
- Upgrade devDependencies.

## [1.1.0] - 2019-06-28
### Changed
- Upgrade mercury version
Expand Down
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ npm i @xbyorange/mercury-memory --save

## Api

`new Memory(object[, id])`
`new Memory(defaultValue[, options || uuid][, options])`
* Arguments
* object - _`<Object>`_. Object to be stored. Default value is assigned too at the same time.
* id - _`<String>`_ Id of the Mercury Object. Optional, only useful for debugging purposes.
* defaultValue - _`<Object>`_. Object to be stored. Default value is assigned too at the same time.
* uuid - _`<String>`_. Unique id to assign to returned Mercury instance. Useful when using [mercury `sources` handler][mercury-sources-docs-url]. __To be deprecated in next releases. Options object should be passed as second argument instead of uuid.__
* options - `<Object>` containing properties:
* queriesDefaultValue - _`<Boolean>`_ If `true`, the default value of queried sources will be the value of the "key" in the query. If not defined, the default value of queried sources will be the full `defaultValue` object.
* uuid - _`<String>`_ Unique id to assign to returned Mercury instance. Useful when using [mercury `sources` handler][mercury-sources-docs-url].
* tags - _`<String> or <Array of Strings>`_ Tags to assign to the instance. Useful when using [mercury `sources` handler][mercury-sources-docs-url]. A "memory" tag will be always added to provided tags by default.

## Methods

Expand All @@ -34,12 +38,34 @@ npm i @xbyorange/mercury-memory --save
* Arguments
* key - `<String>` Key of the memory object to be read, updated, created or deleted.

### cache
## Cache

The `clean` events will be dispatched when the `update`, `delete` or `create` methods are executed for an specific query as in other mercury origins:
All cache will be cleaned when the `update`, `delete` or `create` methods are executed for any specific query.

* If `update` or `delete` methods are executed over the origin without query, cache of all queried resources will be cleaned too.
* All `cache` will be cleaned if the `create` method is executed.
## Default value

The default value of a "queried" instance will be the complete `defaultValue` object until the "queriesDefaultValue" option is set as `true`, in which case the default value will be the value of the key corresponding to the query:

```js
import { Memory } from "@xbyorange/mercury-memory";

const fooMemory = new Memory({
foo: "foo-value",
var: "var-value"
});

console.log(fooMemory.query("foo").read.value) // {foo: "foo-value", var: "var-value"}

const fooMemory2 = new Memory({
foo: "foo-value",
var: "var-value"
}, {
queriesDefaultValue: true
});

console.log(fooMemory.query("foo").read.value) // "foo"

```

## Examples

Expand Down Expand Up @@ -111,6 +137,7 @@ Contributors are welcome.
Please read the [contributing guidelines](.github/CONTRIBUTING.md) and [code of conduct](.github/CODE_OF_CONDUCT.md).

[mercury-url]: https://github.com/xbyorange/mercury
[mercury-sources-docs-url]: https://github.com/XbyOrange/mercury/blob/master/docs/sources/api.md

[coveralls-image]: https://coveralls.io/repos/github/XbyOrange/mercury-memory/badge.svg
[coveralls-url]: https://coveralls.io/github/XbyOrange/mercury-memory
Expand Down

0 comments on commit a24de51

Please sign in to comment.