Skip to content

Commit b6eb629

Browse files
committed
more minor code style updates
- fix some more code style issues that were unnoticed in couple of latest commits
1 parent d4baf6a commit b6eb629

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
=== master
22

3+
More minor code style updates
4+
35
Small fix for form in demo app
46

57
Small code style updates

src/Form.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default class Form extends (PureComponent || Component) {
2626
state = { errors: {} };
2727
validations = {};
2828
validator = buildFormValidator(this);
29-
cache = buildHandlersCache();
29+
_handlersCache = buildHandlersCache();
3030

3131
componentWillReceiveProps() {
3232
if (this._nextErrors) {
@@ -47,10 +47,10 @@ export default class Form extends (PureComponent || Component) {
4747
}
4848

4949
$(name) {
50-
const handler = this.cache.fetch(name, () => this.set.bind(this, name));
50+
const handler = this._handlersCache.fetch(name, () => this.set.bind(this, name));
5151

5252
const wrapper = (handler, ...bindings) => {
53-
wrapper.onChange = this.cache.fetch([name, handler, ...bindings], () => {
53+
wrapper.onChange = this._handlersCache.fetch([name, handler, ...bindings], () => {
5454
return handler.hasOwnProperty('prototype') ? handler.bind(this, ...bindings) : handler;
5555
});
5656

src/utils.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,11 @@ class Cache {
142142
}
143143

144144
fetchSimple(key, setter) {
145-
if (this.store[key]) {
146-
return this.store[key];
147-
} else {
145+
if (!(key in this.store)) {
148146
this.store[key] = setter();
149-
return this.store[key];
150147
}
148+
149+
return this.store[key];
151150
}
152151

153152
fetchComplex([name, ...path], setter) {
@@ -157,6 +156,7 @@ class Cache {
157156
for (let i = 0; i < path.length - 1; i++) {
158157
if (typeof this.get(current, path[i]) === 'undefined') {
159158
const nextKey = path[i + 1];
159+
160160
this.put(current, path[i],
161161
typeof nextKey === 'number' ||
162162
typeof nextKey === 'string' ||
@@ -167,11 +167,12 @@ class Cache {
167167
current = this.get(current, path[i]);
168168
}
169169
const key = path[path.length - 1], cached = this.get(current, key);
170+
170171
return cached || this.put(current, key, setter());
171172
}
172173

173174
get(store, key) {
174-
if (store.constructor === WeakMap) {
175+
if (store instanceof WeakMap) {
175176
return store.get(key);
176177
} else {
177178
return store[key];
@@ -184,6 +185,7 @@ class Cache {
184185
} else {
185186
store[key] = value;
186187
}
188+
187189
return value;
188190
}
189191
}

0 commit comments

Comments
 (0)