Skip to content

Commit 0e4e820

Browse files
committed
support plain javascript objects
1 parent e9a14e5 commit 0e4e820

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

addon/components/x-tree-children.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Component from '@ember/component';
22
import layout from '../templates/components/x-tree-children';
3-
import { get, setProperties } from '@ember/object';
3+
import { setProperties } from '@ember/object';
44

55
export default Component.extend({
66
layout,
@@ -9,9 +9,9 @@ export default Component.extend({
99

1010
actions: {
1111
updateCheckbox() {
12-
if (this.get('recursiveCheck')) {
13-
let model = this.get('model');
14-
let children = get(model, 'children');
12+
if (this.recursiveCheck) {
13+
let model = this.model;
14+
let children = model.children;
1515

1616
if (children.length) {
1717
let isChecked = false;

addon/components/x-tree-node.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Component from '@ember/component';
2-
import { computed, get, setProperties } from '@ember/object';
2+
import { computed, set, setProperties } from '@ember/object';
33
import layout from '../templates/components/x-tree-node';
44

55
export default Component.extend({
@@ -13,45 +13,45 @@ export default Component.extend({
1313
recursiveCheck: false,
1414

1515
isChosen: computed('model.id', 'chosenId', function() {
16-
return this.get('model.id') === this.get('chosenId');
16+
return this.model.id === this.chosenId;
1717
}),
1818

1919
click() {
20-
let select = this.get('onSelect');
20+
let select = this.onSelect;
2121
if (select) {
22-
let model = this.get('model');
23-
let wasChecked = model.get('isChecked');
22+
let model = this.model;
23+
let wasChecked = model.isChecked;
2424

2525
select(model);
2626

27-
let isChecked = model.get('isChecked');
28-
if (isChecked !== wasChecked && this.get('recursiveCheck')) {
27+
let isChecked = model.isChecked;
28+
if (isChecked !== wasChecked && this.recursiveCheck) {
2929
this.setChildCheckboxesRecursively(model, isChecked);
3030
this.updateCheckbox();
3131
}
3232
}
3333
},
3434

3535
mouseEnter() {
36-
this.set('model.isSelected', true);
36+
set(this, 'model.isSelected', true);
3737

38-
let hover = this.get('onHover');
38+
let hover = this.onHover;
3939
if (hover) {
40-
hover(this.get('model'));
40+
hover(this.model);
4141
}
4242
},
4343

4444
mouseLeave() {
45-
this.set('model.isSelected', false);
45+
set(this, 'model.isSelected', false);
4646

47-
let hoverOut = this.get('onHoverOut');
47+
let hoverOut = this.onHoverOut;
4848
if (hoverOut) {
49-
hoverOut(this.get('model'));
49+
hoverOut(this.model);
5050
}
5151
},
5252

5353
setChildCheckboxesRecursively(node, isChecked) {
54-
let children = get(node, 'children');
54+
let children = node.children;
5555
if (children.length) {
5656
children.forEach(child => {
5757
setProperties(child, {
@@ -69,14 +69,14 @@ export default Component.extend({
6969
event.stopPropagation();
7070

7171
let isChecked = this.toggleProperty('model.isChecked');
72-
let model = this.get('model');
72+
let model = this.model;
7373

74-
if (this.get('recursiveCheck')) {
74+
if (this.recursiveCheck) {
7575
this.setChildCheckboxesRecursively(model, isChecked);
7676
this.updateCheckbox();
7777
}
7878

79-
let check = this.get('onCheck');
79+
let check = this.onCheck;
8080
if (check) {
8181
check(model);
8282
}

addon/components/x-tree.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Component from '@ember/component';
22
import layout from '../templates/components/x-tree';
33
import { getDescendents, getAncestors } from '../utils/tree';
4-
import { get, set } from '@ember/object';
4+
import { set } from '@ember/object';
55

66
export default Component.extend({
77
layout,
@@ -14,23 +14,23 @@ export default Component.extend({
1414

1515
init() {
1616
this._super(...arguments);
17-
let tree = this.get('model');
17+
let tree = this.model;
1818

1919
// Make sure chosen item is highlighted and expanded-to in the tree
20-
let chosenId = this.get('chosenId');
20+
let chosenId = this.chosenId;
2121
if (chosenId) {
2222
let chosen = getDescendents(tree).findBy('id', chosenId);
2323
if (chosen) {
2424
getAncestors(tree, chosen).forEach(x => {
25-
if (get(x, 'id') !== chosenId) {
25+
if (x.id !== chosenId) {
2626
set(x, 'isExpanded', true);
2727
}
2828
});
2929
}
3030
}
3131

3232
// Expand to given depth
33-
let expandDepth = this.get('expandDepth');
33+
let expandDepth = this.expandDepth;
3434
if (expandDepth) {
3535
getDescendents(tree, expandDepth).setEach('isExpanded', true);
3636
}

addon/utils/tree.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ export function buildTree(model, options = {}) {
3131

3232
// Defaults
3333
set(node, 'children', A());
34-
set(node, 'isVisible', get(node, 'isVisible') || true);
35-
set(node, 'isExpanded', get(node, 'isExpanded') || false);
34+
set(node, 'isVisible', node.isVisible || true);
35+
set(node, 'isExpanded', node.isExpanded || false);
3636

37-
tree[get(node, 'id')] = node;
37+
tree[node.id] = node;
3838
});
3939

4040
// Connect all children to their parent
4141
model.forEach(node => {
4242
let child = tree[get(node, options.valueKey || 'id')];
43-
let parent = get(node, 'parentId');
43+
let parent = node.parentId;
4444

4545
if (isEmpty(parent)) {
4646
roots.pushObject(child);
@@ -74,7 +74,7 @@ export function getDescendents(tree, depth = -1) {
7474
// Returns a flat list of ancestors, including the child
7575
export function getAncestors(tree, childNode) {
7676
let ancestors = A();
77-
let childId = get(childNode, 'id');
77+
let childId = childNode.id;
7878

7979
tree.forEach(node => {
8080
if (!ancestors.isAny('id', childId)) {
@@ -94,5 +94,5 @@ export function getAncestors(tree, childNode) {
9494

9595
// Returns the parent of a child
9696
export function getParent(list, childNode) {
97-
return list.find(x => x.children.find(y => y.id === childNode.get('id')));
97+
return list.find(x => x.children.find(y => y.id === childNode.id));
9898
}

0 commit comments

Comments
 (0)