Skip to content

Commit 15e444e

Browse files
releases/v2.8.0
- [0ffad7d][michaeljymsgutierrez]: Updated release version from v2.7.0 to v2.8.0 - 2026-04-22 22:09:20 - [a1f0db2][Chael Gutierrez]: Features/record rollback attributes (#236) - 2026-04-19 02:40:11
1 parent bb491db commit 15e444e

18 files changed

Lines changed: 258 additions & 36 deletions

File tree

DOCS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ to provide additional configuration for the request.</p>
155155
<dd><p>Reloads a record from the server.</p>
156156
<p>Fetches the latest data for the specified record and updates the local copy.</p>
157157
</dd>
158+
<dt><a href="#_rollbackRecordAttributes">_rollbackRecordAttributes()</a> ⇒ <code>void</code> ℗</dt>
159+
<dd><p>Reverts the record&#39;s attributes to their original state.</p>
160+
<p>This method retrieves the stored <code>originalRecord</code> (excluding internal
161+
ARM properties), applies those values back to the current record instance,
162+
and resets the <code>isDirty</code> and <code>isPristine</code> state flags.</p>
163+
</dd>
158164
<dt><a href="#_getCollectionRecord">_getCollectionRecord(collectionName, [collectionConfig], currentRecord)</a> ⇒ <code>Object</code> | <code>Array</code> ℗</dt>
159165
<dd><p>Retrieves records from a specified collection based on given criteria.</p>
160166
<p>This method retrieves records from the collection with the specified
@@ -915,6 +921,17 @@ Fetches the latest data for the specified record and updates the local copy.
915921
| currentRecord | <code>Object</code> | | The record to reload. |
916922
| [collectionConfig] | <code>Object</code> | <code>{}</code> | Optional configuration for the collection. |
917923

924+
<a name="_rollbackRecordAttributes"></a>
925+
926+
## \_rollbackRecordAttributes() ⇒ <code>void</code> ℗
927+
Reverts the record's attributes to their original state.
928+
929+
This method retrieves the stored `originalRecord` (excluding internal
930+
ARM properties), applies those values back to the current record instance,
931+
and resets the `isDirty` and `isPristine` state flags.
932+
933+
**Kind**: global function
934+
**Access**: private
918935
<a name="_getCollectionRecord"></a>
919936

920937
## \_getCollectionRecord(collectionName, [collectionConfig], currentRecord) ⇒ <code>Object</code> \| <code>Array</code> ℗

README.md

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<img src="https://github.com/michaeljymsgutierrez/arm-js-library/actions/workflows/ci-cd.yml/badge.svg" alt="cicd-badge-logo" />
1010
</a>
1111
<a href="https://www.npmjs.com/package/arm-js-library">
12-
<img src="https://img.shields.io/badge/npm_version-2.7.0-blue" alt="npm-badge-logo" />
12+
<img src="https://img.shields.io/badge/npm_version-2.8.0-blue" alt="npm-badge-logo" />
1313
</a>
1414
<a href="https://github.com/michaeljymsgutierrez/arm-js-library?tab=MIT-1-ov-file">
1515
<img src="https://img.shields.io/badge/license-MIT-green" alt="license-badge-logo" />
@@ -604,7 +604,7 @@ See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/m
604604
"type": "addresses",
605605
"attributes": {
606606
"address1": "Test Address 1",
607-
"address2": "171872.7.0222",
607+
"address2": "171872.8.0222",
608608
"kind": "office",
609609
"label": "Anabu Hills",
610610
"latitude": "14.394261",
@@ -702,7 +702,7 @@ See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/m
702702
address.get('attributes.label')
703703
```
704704
705-
- **Request Functions**
705+
- **Request and Retrieve Functions**
706706
- **save(collectionConfig)**
707707
- Persist collection record changes to server.
708708
- Create a new record to server only if it doesn't already exist in the database.
@@ -711,7 +711,7 @@ See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/m
711711
- Will call **PUT** method: `PUT /addresses/2519858`
712712
- Support collectionConfig. - **optional**
713713
- Available collectionConfig `(skip, alias, autoResolve, ignorePayload, override)`
714-
- See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/main/apps/create-next-app/src/app/demo/collection-records/request-functions/save)
714+
- See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/main/apps/create-next-app/src/app/demo/collection-records/request-retrieve-functions/save)
715715
716716
```javascript
717717
// Returned promise
@@ -727,7 +727,7 @@ See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/m
727727
- Will call **GET** method: `GET /addresses/2519858`
728728
- Support collectionConfig. - **optional**
729729
- Available collectionConfig `(skip, alias, autoResolve, ignorePayload, override)`
730-
- See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/main/apps/create-next-app/src/app/demo/collection-records/request-functions/reload)
730+
- See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/main/apps/create-next-app/src/app/demo/collection-records/request-retrieve-functions/reload)
731731
732732
```javascript
733733
// Returned promise
@@ -741,12 +741,20 @@ See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/m
741741
})
742742
```
743743
744+
- **rollbackAttributes()**
745+
- Rollback record attributes to their original state without triggering a request.
746+
- See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/main/apps/create-next-app/src/app/demo/collection-records/request-retrieve-functions/rollback-attributes)
747+
748+
```javascript
749+
address.rollbackAttributes()
750+
```
751+
744752
- **destroyRecord(collectionConfig)**
745753
- Remove collection record permanently from server.
746754
- Will call **GET** method: `DELETE /addresses/2519858`
747755
- Support collectionConfig. - **optional**
748756
- Available collectionConfig `(skip, alias, autoResolve, ignorePayload, override)`
749-
- See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/main/apps/create-next-app/src/app/demo/collection-records/request-functions/destroy-record)
757+
- See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/main/apps/create-next-app/src/app/demo/collection-records/request-retrieve-functions/destroy-record)
750758
751759
```javascript
752760
// Returned promise
@@ -779,7 +787,7 @@ See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/m
779787
- Sort returned collection records based on passed array of sort criteria.
780788
- **config - Object**
781789
- Contains request config such as `(skip, alias, autoResolve, ignorePayload, override)` which are currently available.
782-
- See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/main/apps/create-next-app/src/app/demo/collection-records/request-functions/get-collection)
790+
- See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/main/apps/create-next-app/src/app/demo/collection-records/request-retrieve-functions/get-collection)
783791
784792
```javascript
785793
// Get user record from the server but don't preload addresses records.
@@ -1056,26 +1064,9 @@ const addresses = [
10561064
10571065
## Credits
10581066
1059-
<a href="https://www.facebook.com/skpcls" title="Axl Asuncion (Graphic Artist) - Original logo/design creator">
1060-
<img
1061-
src="https://assets-omega-neon.vercel.app/images/axl.png"
1062-
alt="Axl Asuncion"
1063-
height="40" width="40" />
1064-
</a>
1065-
1066-
<a href="https://github.com/luigircruz" title="Luigi Cruz (Developer) - Features and bugs feedback" >
1067-
<img
1068-
src="https://assets-omega-neon.vercel.app/images/luigi.png"
1069-
alt="Luigi Cruz"
1070-
height="40" width="40" />
1071-
</a>
1072-
1073-
<a href="https://github.com/DicksonPal" title="Dickson Palomeras (Developer) - Features and bugs feedback" >
1074-
<img
1075-
src="https://assets-omega-neon.vercel.app/images/dickson.png"
1076-
alt="Dickson Palomeras"
1077-
height="40" width="40" />
1078-
</a>
1067+
- **[Axl Asuncion](https://www.facebook.com/skpcls)** - Original logo/design creator
1068+
- **[Luigi Cruz](https://github.com/luigircruz)** - Features and bugs feedback
1069+
- **[Dickson Palomeras](https://github.com/DicksonPal)** - Features and bugs feedback
10791070
10801071
## License
10811072

apps/create-next-app/src/app/demo/collection-records/request-functions/destroy-record/model.js renamed to apps/create-next-app/src/app/demo/collection-records/request-retrieve-functions/destroy-record/model.js

File renamed without changes.

apps/create-next-app/src/app/demo/collection-records/request-functions/destroy-record/page.jsx renamed to apps/create-next-app/src/app/demo/collection-records/request-retrieve-functions/destroy-record/page.jsx

File renamed without changes.

apps/create-next-app/src/app/demo/collection-records/request-functions/get-collection/model.js renamed to apps/create-next-app/src/app/demo/collection-records/request-retrieve-functions/get-collection/model.js

File renamed without changes.

apps/create-next-app/src/app/demo/collection-records/request-functions/get-collection/page.jsx renamed to apps/create-next-app/src/app/demo/collection-records/request-retrieve-functions/get-collection/page.jsx

File renamed without changes.

apps/create-next-app/src/app/demo/collection-records/request-functions/reload/model.js renamed to apps/create-next-app/src/app/demo/collection-records/request-retrieve-functions/reload/model.js

File renamed without changes.

apps/create-next-app/src/app/demo/collection-records/request-functions/reload/page.jsx renamed to apps/create-next-app/src/app/demo/collection-records/request-retrieve-functions/reload/page.jsx

File renamed without changes.

apps/create-next-app/src/app/demo/collection-records/request-functions/save/model.js renamed to apps/create-next-app/src/app/demo/collection-records/request-retrieve-functions/rollback-attributes/model.js

File renamed without changes.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
'use client'
2+
3+
import { observer } from 'mobx-react'
4+
import Model from './model'
5+
6+
const Page = observer(() => {
7+
const { isLoading, data: address } = Model()
8+
9+
if (isLoading) return <div>Loading...</div>
10+
11+
return (
12+
<form onSubmit={(event) => event.preventDefault()}>
13+
<div className="form-control">
14+
<label htmlFor="address1">Address1</label>
15+
<input
16+
type="text"
17+
name="address1"
18+
value={address.get('attributes.address1') ?? ''}
19+
onChange={(event) =>
20+
address.set('attributes.address1', event.target.value)
21+
}
22+
/>
23+
</div>
24+
25+
<div className="form-control">
26+
<label htmlFor="address2">Address2</label>
27+
<input
28+
type="text"
29+
name="address2"
30+
value={address.get('attributes.address2') ?? ''}
31+
onChange={(event) =>
32+
address.set('attributes.address2', event.target.value)
33+
}
34+
/>
35+
</div>
36+
37+
<div className="form-control">
38+
<label htmlFor="city">City</label>
39+
<input
40+
type="text"
41+
name="city"
42+
value={address.get('attributes.city') ?? ''}
43+
onChange={(event) =>
44+
address.set('attributes.city', event.target.value)
45+
}
46+
/>
47+
</div>
48+
49+
<div className="form-control">
50+
<label htmlFor="post-code">Post code</label>
51+
<input
52+
type="text"
53+
name="post-code"
54+
value={address.get('attributes.post-code') ?? ''}
55+
onChange={(event) =>
56+
address.set('attributes.post-code', event.target.value)
57+
}
58+
/>
59+
</div>
60+
61+
<div className="form-control">
62+
<label htmlFor="landmark">Landmark</label>
63+
<input
64+
type="text"
65+
name="landmark"
66+
value={address.get('attributes.landmark') ?? ''}
67+
onChange={(event) =>
68+
address.set('attributes.landmark', event.target.value)
69+
}
70+
/>
71+
</div>
72+
73+
<div className="form-control">
74+
<label htmlFor="kind">Kind</label>
75+
<input
76+
type="text"
77+
name="kind"
78+
value={address.get('attributes.kind') ?? ''}
79+
onChange={(event) =>
80+
address.set('attributes.kind', event.target.value)
81+
}
82+
/>
83+
</div>
84+
85+
<div className="form-control">
86+
<label htmlFor="label">Label</label>
87+
<input
88+
type="text"
89+
name="label"
90+
value={address.get('attributes.label') ?? ''}
91+
onChange={(event) =>
92+
address.set('attributes.label', event.target.value)
93+
}
94+
/>
95+
</div>
96+
97+
<div className="form-control">
98+
<label htmlFor="latitude">Latitude</label>
99+
<input
100+
type="text"
101+
name="latitude"
102+
value={address.get('attributes.latitude')}
103+
onChange={(event) =>
104+
address.set('attributes.latitude', event.target.value)
105+
}
106+
/>
107+
</div>
108+
109+
<div className="form-control">
110+
<label htmlFor="longitude">Longitude</label>
111+
<input
112+
type="text"
113+
name="longitude"
114+
value={address.get('attributes.longitude')}
115+
onChange={(event) =>
116+
address.set('attributes.longitude', event.target.value)
117+
}
118+
/>
119+
</div>
120+
121+
<div className="form-control">
122+
<button
123+
className="blue-btn"
124+
onClick={() => address.rollbackAttributes()}>
125+
Rollback Attributes
126+
</button>
127+
</div>
128+
</form>
129+
)
130+
})
131+
132+
export default Page

0 commit comments

Comments
 (0)