Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/3.0.0 #56

Merged
merged 36 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2410794
The road to 3.0
masylum Aug 19, 2018
79995b7
More items
masylum Aug 19, 2018
976a6b5
Update flow and fix tests
masylum Aug 20, 2018
604ae0a
Reimplement mustGet and mustFind
geclos May 9, 2019
3cfe81b
reimplemented mustGet and mustFind methods
geclos May 9, 2019
1285bbf
Added progress for latest request
geclos May 10, 2019
e69d1cc
Updated changelog
geclos May 10, 2019
f5bee17
Update CHANGELOG.md
geclos May 10, 2019
09231a6
Changed RPC signature to provide custom label as an optional value
geclos May 10, 2019
c64b977
OCD
geclos May 10, 2019
657ac9d
added documentation for missing methods
geclos May 10, 2019
4f9b0e4
removed unnecessary return values in some promises
geclos May 10, 2019
26f1397
Attempt to fix #47
geclos May 10, 2019
b2aacff
Accept a rootUrl in rpc endpoints. fix #41.
geclos May 10, 2019
103bb83
Remove flow #1
geclos May 17, 2019
61b1d46
Migrate to typescript 🎉
geclos May 17, 2019
2b2252c
updated changelog
geclos May 17, 2019
03fd8cb
Migrated tests to Typescript
geclos May 17, 2019
b15ee5a
updated travis config
geclos May 20, 2019
3107ae2
added abstract declaration to map method
geclos May 20, 2019
7106bb3
added some scripts
geclos May 20, 2019
b3df66c
code review
geclos May 20, 2019
02a4a1a
target ES5
geclos May 20, 2019
0c9f165
Update README.md
geclos May 20, 2019
a389d82
tweak README
geclos May 20, 2019
931f51f
bump version!
geclos May 20, 2019
1f794b0
bundle type declarations with package
geclos May 20, 2019
43d448c
more README improvements
geclos May 20, 2019
94ecd88
udpate CHANGELOG
geclos May 20, 2019
cf2b5e2
updated npmignore
geclos May 20, 2019
6fbb666
Include payload as a fallback in case of API error
geclos May 21, 2019
311a933
add custom paylaod to ErrorObject
geclos May 21, 2019
0e0f2e8
add() returns array of added models
geclos May 21, 2019
0911748
removed TODOs
geclos May 21, 2019
969fc69
Defend against requesting patch during a POST operation
geclos May 21, 2019
2a5c2db
Updated CHANGELOG
geclos May 29, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .babelrc

This file was deleted.

16 changes: 3 additions & 13 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
parser: 'babel-eslint',
plugins: [ 'flowtype' ],
parser: '@typescript-eslint/parser',
plugins: [ '@typescript-eslint' ],

env: {
browser: true,
Expand All @@ -18,20 +18,10 @@ module.exports = {
}
},

extends: [
'plugin:flowtype/recommended',
'standard'
],

rules: {
'object-curly-spacing': ['warn', 'always'],
'prefer-promise-reject-errors': 'off',
'no-duplicate-imports': 'off',
'flowtype/no-weak-types': [0, {
'any': false,
'Object': false,
'Function': false
}]
'no-duplicate-imports': 'off'
}
};

10 changes: 0 additions & 10 deletions .flowconfig

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ coverage/
node_modules/
flow-typed/
.eslintcache
*.log
*.swp
*.rpt2*
30 changes: 28 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
src/
.babelrc
*.log
npm-debug.log*

# Coverage directory used by tools like istanbul
coverage
.nyc_output

# Dependency directories
node_modules

# npm package lock
package-lock.json
yarn.lock

# project files
src
__tests__
.rpt2_cache
CHANGELOG.md
.editorconfig
.eslintcache
.eslintignore
.eslintrc.js
.gitignore
.travis.yml
rollup.config.js
tsconfig.json

6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
language: node_js
cache:
yarn: true
directories:
- node_modules
node_js:
- "6.3.0"
- "10.15.3"
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Changelog

## `3.0.0`
New features 🎩:
- Reimplemented `mustFind` and `mustGet` methods in Collection.
- Brought back the `request` attribute in Model. The attribute tracks the last issued request.
- Brought back `onProgress` hook in `save` method.

Solved bugs 🐛:
- Fix https://github.com/masylum/mobx-rest/issues/47
- Fix https://github.com/masylum/mobx-rest/issues/41

What's changed 💅:
- Migrated to Typescript
- Made RPC label optional with a default `fetching` value

Breaking changes ☢️:
- Migrated to Mobx 5+
- Rollback default `keepChanges` flag value to `false`.

## `3.0.0.alpha`

:sparkles:

Full description here: https://github.com/masylum/mobx-rest/pull/39
Kudos to @rdiazv

## `2.2.5`

:nail_care:
Expand Down
128 changes: 117 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class User extends Model {
}
```

#### `defaultAttributes: Object`

An object literal that holds the default attributes of the model. {} by default.

#### `attributes: ObservableMap`

An `ObservableMap` that holds the attributes of the model.
Expand Down Expand Up @@ -134,6 +138,71 @@ request with the given label.

Example: `file.isRequest('saving')`

#### changedAttributes: Array<string>

Get an array with the attributes names that have changed.

Example:
```js
model.set({ name: 'Pau'})

model.changedAttributes // => ['name']
```

#### changes: { [string]: any }

Gets the current changes.

Example:
```js
model.set({ name: 'Pau'})

model.changes // => { name: 'Pau' }
```

#### hasChanges(attribute?: string): boolean

If an attribute is specified, returns true if it has changes.
If no attribute is specified, returns true if any attribute has changes.

Example:
```js
model.set({ name: 'Pau'})

// with attribute
model.hasChanges('name') // => true

// without attribute
model.hasChanges() // => true
```

#### commitChanges(): void

Commit attributes to model.

Example:
```js
model.set({ name: 'Pau' })
model.hasChanges // => true

model.commitChanges()
model.hasChanges // => false
```

#### discardChanges(): void

This will reset the model attributes to the last committed ones.

Example:
```js
const model = new Model({ name: 'Foo' })
model.set({ name: 'Pau' })
model.get('name') // => Pau

model.discardChanges()
model.get('name') // => 'Foo'
```

#### `isNew: boolean`

Return whether that model has been synchronized with the server or not.
Expand Down Expand Up @@ -234,7 +303,7 @@ Options:
- `optimistic = true` Whether we want to delete the resource in the client
first or wait for the server's response.

#### `rpc(method: 'string', body: {}): Promise`
#### `rpc(method: 'string', body?: {}, label?: 'fetching'): Promise`

When dealing with REST there are always cases when we have some actions beyond
the conventions. Those are represented as `rpc` calls and are not opinionated.
Expand Down Expand Up @@ -301,7 +370,7 @@ Example:
filesCollection.isRequest('saving')
```

#### `isEmpty(): boolean`
#### `isEmpty: boolean`

Helper method that asks the collection whether there is any
model in it.
Expand All @@ -320,11 +389,15 @@ usersCollection.models.length // => 10

Find a model at the given position.

#### `get(id: number): ?Model`
#### `get(id: number, { required?: boolean = false }): ?Model`

Find a model (or not) with the given id. If `required` it will raise an error if not found.

Find a model (or not) with the given id.
#### `mustGet(id: number): Model`

#### `filter(query: Object): Array<Model>`
Find a model with the given id or raise an Error.

#### `filter(query: Object | Function): Array<Model>`

Helper method that filters the collection by the given conditions represented
as a key value.
Expand All @@ -336,35 +409,48 @@ const resolvedTasks = tasksCollection.filter({ resolved: true })
resolvedTasks.length // => 3
```

#### `find(query: Object): ?Model`
#### `find(query: Object, { required?: boolean = false }): ?Model`

Same as `filter` but it will halt and return when the first model matches
the conditions.
the conditions. If `required` it will raise an error if not found.
geclos marked this conversation as resolved.
Show resolved Hide resolved

Example:

```js
const pau = usersCollection.find({ name: 'pau' })
pau.get('name') // => 'pau'

usersCollection.find({ name: 'foo'}) // => Error(`Invariant: Model must be found`)
```

#### `mustFind(query: Object): Model`

Same as `find` but it will raise an Error if the model is not found.

Example:

```js
const pau = usersCollection.mustFind({ name: 'pau' })
pau.get('name') // => 'pau'
```

#### `add(data: Array<Object>): Array<Model>`
#### `add(data: Array<Object|T>|T|Object): Array<Model>`

Adds models with the given array of attributes.

```js
usersCollection.add([{id: 1, name: 'foo'}])
```

#### `reset(data: Array<Object>): Array<Model>`
#### `reset(data: Array<Object|T>): Array<Model>`

Resets the collection with the given models.

```js
usersCollection.reset([{id: 1, name: 'foo'}])
```

#### `remove(ids: Array<number>): void`
#### `remove(ids: Array<number|T>|number|T): void`

Remove any model with the given ids.

Expand Down Expand Up @@ -399,7 +485,7 @@ companiesCollection.get(2).get('name') // => 'Factorial'
companiesCollection.get(3) // => null
```

#### `build(attributes: Object): Model`
#### `build(attributes: Object|T): Model`

Instantiates and links a model to the current collection.

Expand Down Expand Up @@ -444,6 +530,26 @@ tasksCollection.isEmpty() // => false

Exactly the same as the model one, but at the collection level.

### forEach (callback: (model: T) => void): void

Alias for models.forEach

Example: `collection.forEach(model => console.log(model.get('id')))`

### map<P> (callback: (model: T) => P): Array<P>

Alias for models.map

Example: `collection.map(model => model.get('id')) // => [1,2,3...]`

### peek (): Array<T: Model>

Returns a shallow array representation of the collection

### slice (): Array<T: Model>

Returns a defensive shallow array representation of the collection

### `apiClient`

This is the object that is going to make the `xhr` requests to interact with your API.
Expand Down
Loading