-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13658da
commit 6e9e5d3
Showing
4 changed files
with
73 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import Ember from 'ember'; | ||
import { | ||
A as emberArray, | ||
isEmberArray as isArray | ||
} from 'ember-array/utils'; | ||
import Helper from 'ember-helper'; | ||
import { guidFor } from 'ember-metal/utils'; | ||
import computed from 'ember-computed'; | ||
import observer from 'ember-metal/observer'; | ||
import get from 'ember-metal/get'; | ||
import set from 'ember-metal/set'; | ||
import { isEmpty } from 'ember-utils'; | ||
|
||
const { defineProperty } = Ember; | ||
const idForArray = (array) => `__array-${guidFor(array)}`; | ||
|
||
export default function(multiArrayComputed) { | ||
return Helper.extend({ | ||
compute([...arrays]) { | ||
set(this, 'arrays', arrays.map((obj) => { | ||
if (isArray(obj)) { | ||
return emberArray(obj) | ||
} | ||
|
||
return obj; | ||
})); | ||
|
||
return get(this, 'content'); | ||
}, | ||
|
||
valuesDidChange: observer('arrays.[]', function() { | ||
this._recomputeArrayKeys(); | ||
|
||
let arrays = get(this, 'arrays'); | ||
let arrayKeys = get(this, 'arrayKeys'); | ||
|
||
if (isEmpty(arrays)) { | ||
defineProperty(this, 'content', []); | ||
return; | ||
} | ||
|
||
defineProperty(this, 'content', multiArrayComputed(...arrayKeys)); | ||
}), | ||
|
||
contentDidChange: observer('content.[]', function() { | ||
this.recompute(); | ||
}), | ||
|
||
_recomputeArrayKeys() { | ||
let arrays = get(this, 'arrays'); | ||
|
||
let oldArrayKeys = get(this, 'arrayKeys') || []; | ||
let newArrayKeys = arrays.map(idForArray); | ||
|
||
let keysToRemove = oldArrayKeys.filter((key) => { | ||
return newArrayKeys.indexOf(key) === -1; | ||
}); | ||
|
||
keysToRemove.forEach((key) => set(this, key, null)); | ||
arrays.forEach((array) => set(this, idForArray(array), array)); | ||
|
||
set(this, 'arrayKeys', newArrayKeys); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,4 @@ | ||
import Ember from 'ember'; | ||
import { A as emberArray } from 'ember-array/utils'; | ||
import { intersect } from 'ember-computed'; | ||
import Helper from 'ember-helper'; | ||
import get from 'ember-metal/get'; | ||
import observer from 'ember-metal/observer'; | ||
import set from 'ember-metal/set'; | ||
import { guidFor } from 'ember-metal/utils'; | ||
import { isEmpty } from 'ember-utils'; | ||
import createMultiArrayHelper from '../-private/create-multi-array-helper'; | ||
|
||
const { defineProperty } = Ember; | ||
|
||
const idForArray = (array) => `__array-${guidFor(array)}`; | ||
|
||
export default Helper.extend({ | ||
compute([...arrays]) { | ||
set(this, 'arrays', arrays); | ||
|
||
return get(this, 'content'); | ||
}, | ||
|
||
arraysDidChange: observer('arrays.[]', function() { | ||
let arrays = get(this, 'arrays'); | ||
|
||
let oldArrayKeys = get(this, 'arrayKeys') || []; | ||
let newArrayKeys = arrays.map(idForArray); | ||
|
||
let keysToRemove = oldArrayKeys.filter((key) => { | ||
return newArrayKeys.indexOf(key) === -1; | ||
}); | ||
|
||
keysToRemove.forEach((key) => set(this, key, null)); | ||
arrays.forEach((array) => set(this, idForArray(array), emberArray(array))); | ||
|
||
set(this, 'arrayKeys', newArrayKeys); | ||
|
||
if (isEmpty(arrays)) { | ||
defineProperty(this, 'content', []); | ||
return; | ||
} | ||
|
||
defineProperty(this, 'content', intersect(...newArrayKeys)); | ||
}), | ||
|
||
contentDidChange: observer('content.[]', function() { | ||
this.recompute(); | ||
}) | ||
}); | ||
export default createMultiArrayHelper(intersect); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,4 @@ | ||
import Ember from 'ember'; | ||
import { A as emberArray } from 'ember-array/utils'; | ||
import { union } from 'ember-computed'; | ||
import Helper from 'ember-helper'; | ||
import get from 'ember-metal/get'; | ||
import observer from 'ember-metal/observer'; | ||
import set from 'ember-metal/set'; | ||
import { guidFor } from 'ember-metal/utils'; | ||
import { isEmpty } from 'ember-utils'; | ||
import createMultiArrayHelper from '../-private/create-multi-array-helper'; | ||
|
||
const { defineProperty } = Ember; | ||
|
||
const idForArray = (array) => `__array-${guidFor(array)}`; | ||
|
||
export default Helper.extend({ | ||
compute([...arrays]) { | ||
set(this, 'arrays', arrays); | ||
|
||
return get(this, 'content'); | ||
}, | ||
|
||
arraysDidChange: observer('arrays.[]', function() { | ||
let arrays = get(this, 'arrays'); | ||
|
||
let oldArrayKeys = get(this, 'arrayKeys') || []; | ||
let newArrayKeys = arrays.map(idForArray); | ||
|
||
let keysToRemove = oldArrayKeys.filter((key) => { | ||
return newArrayKeys.indexOf(key) === -1; | ||
}); | ||
|
||
keysToRemove.forEach((key) => set(this, key, null)); | ||
arrays.forEach((array) => set(this, idForArray(array), emberArray(array))); | ||
|
||
set(this, 'arrayKeys', newArrayKeys); | ||
|
||
if (isEmpty(arrays)) { | ||
defineProperty(this, 'content', []); | ||
return; | ||
} | ||
|
||
defineProperty(this, 'content', union(...newArrayKeys)); | ||
}), | ||
|
||
contentDidChange: observer('content.[]', function() { | ||
this.recompute(); | ||
}) | ||
}); | ||
export default createMultiArrayHelper(union); |