Skip to content

Commit b720488

Browse files
author
Vlad Balin
committed
deprecated model.set( 'attr', val )
1 parent 96ec8cb commit b720488

File tree

10 files changed

+87
-51
lines changed

10 files changed

+87
-51
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ marked.setOptions({
2727
smartLists: true,
2828
smartypants: false,
2929
highlight: function (code, lang) {
30-
return highlight.highlight(lang, code).value
30+
return highlight.highlight(lang || 'javascript', code).value
3131
}
3232
})
3333

docs/index.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,42 @@ <h1 id="getting-started">Getting started</h1>
8181
</ul>
8282
<p>The state defined with Type-R classes is deeply observable and serializable by default. While being an advanced JSON serialization engine handling sophisticated scenarios (like cross-collections many-to-many relationships), Type-R is completely unopinionated on the client-server transport protocol.</p>
8383
<p>Type-R is your perfect M and VM in MVVM and MVC architecture imposing no restrictions on V and C parts.</p>
84+
<pre><code><span class="hljs-keyword">import</span> { define, Record } <span class="hljs-keyword">from</span> <span class="hljs-string">'type-r'</span>
85+
86+
<span class="hljs-keyword">const</span> Email = <span class="hljs-built_in">String</span>.has.check( <span class="hljs-function"><span class="hljs-params">x</span> =&gt;</span> x! || x.indexOf( <span class="hljs-string">'@'</span> ) &gt;= <span class="hljs-number">0</span>, <span class="hljs-string">'Invalid email'</span> );
87+
88+
@define <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Record</span> </span>{
89+
<span class="hljs-keyword">static</span> attributes = {
90+
<span class="hljs-attr">name</span> : <span class="hljs-built_in">String</span>.isRequired,
91+
<span class="hljs-attr">email</span> : Email.isRequired
92+
}
93+
}
94+
95+
@define <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Message</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Record</span> </span>{
96+
<span class="hljs-keyword">static</span> attributes = {
97+
<span class="hljs-attr">created</span> : <span class="hljs-built_in">Date</span>
98+
author : User,
99+
<span class="hljs-attr">to</span> : User.Collection,
100+
<span class="hljs-attr">subject</span> : <span class="hljs-string">''</span>,
101+
<span class="hljs-attr">body</span> : <span class="hljs-string">''</span>
102+
}
103+
}
104+
105+
<span class="hljs-keyword">const</span> msg = <span class="hljs-keyword">new</span> Message();
106+
assert( !msg.isValid() );
107+
108+
msg.on( <span class="hljs-string">'change'</span>, () =&gt; <span class="hljs-built_in">console</span>.log( <span class="hljs-string">"something is changed!"</span> ) );
109+
110+
msg.transaction( <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
111+
msg.author.name = <span class="hljs-string">'John Dee'</span>;
112+
msg.author.email = <span class="hljs-string">'[email protected]'</span>;
113+
114+
assert( msg.isValid() );
115+
});
116+
117+
</code></pre><blockquote>
118+
<p>something is changed!</p>
119+
</blockquote>
84120
<h2 id="installation-and-requirements">Installation and requirements</h2>
85121
<p>Is packed as UMD and ES6 module. No peer dependencies are required.</p>
86122
<p><code>npm install type-r --save-dev</code></p>

docs/index.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,41 @@ The state defined with Type-R classes is deeply observable and serializable by d
2828

2929
Type-R is your perfect M and VM in MVVM and MVC architecture imposing no restrictions on V and C parts.
3030

31+
import { define, Record } from 'type-r'
32+
33+
const Email = String.has.check( x => x! || x.indexOf( '@' ) >= 0, 'Invalid email' );
34+
35+
@define class User extends Record {
36+
static attributes = {
37+
name : String.isRequired,
38+
email : Email.isRequired
39+
}
40+
}
41+
42+
@define class Message extends Record {
43+
static attributes = {
44+
created : Date
45+
author : User,
46+
to : User.Collection,
47+
subject : '',
48+
body : ''
49+
}
50+
}
51+
52+
const msg = new Message();
53+
assert( !msg.isValid() );
54+
55+
msg.on( 'change', () => console.log( "something is changed!" ) );
56+
57+
msg.transaction( () => {
58+
msg.author.name = 'John Dee';
59+
msg.author.email = '[email protected]';
60+
61+
assert( msg.isValid() );
62+
});
63+
> something is changed!
64+
65+
3166
## Installation and requirements
3267

3368
Is packed as UMD and ES6 module. No peer dependencies are required.

lib/record/transaction.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ export declare class Record extends Transactional implements Owner {
9494
get(key: string): any;
9595
toJSON(): Object;
9696
parse(data: any, options?: TransactionOptions): any;
97-
set(key: string, value: any, options?: TransactionOptions): this;
98-
set(attrs: {}, options?: TransactionOptions): this;
9997
deepSet(name: string, value: any, options?: any): this;
10098
transaction(fun: (self: this) => void, options?: TransactionOptions): void;
10199
_createTransaction(a_values: {}, options?: TransactionOptions): Transaction;

lib/record/transaction.js

Lines changed: 4 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)