-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish up conversion and convert TBody
- Loading branch information
Chris Garrett
committed
Apr 11, 2019
1 parent
cdb62d5
commit a443e40
Showing
5 changed files
with
173 additions
and
127 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,37 @@ | ||
import { computed } from '@ember/object'; | ||
|
||
let VALUES = new WeakMap(); | ||
|
||
function valuesFor(obj) { | ||
if (!VALUES.has(obj)) { | ||
VALUES.set(obj, Object.create(null)); | ||
} | ||
|
||
return VALUES.get(obj); | ||
} | ||
|
||
export default function defaultTo(defaultValue) { | ||
return computed({ | ||
get(key) { | ||
let values = valuesFor(this); | ||
|
||
if (!(key in values)) { | ||
values[key] = typeof defaultValue === 'function' ? defaultValue() : defaultValue; | ||
} | ||
|
||
return defaultValue; | ||
}, | ||
|
||
set(key, value) { | ||
let values = valuesFor(this); | ||
|
||
if (value === undefined) { | ||
values[key] = typeof defaultValue === 'function' ? defaultValue() : defaultValue; | ||
} else { | ||
values[key] = value; | ||
} | ||
|
||
return values[key]; | ||
}, | ||
}); | ||
} |
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
Oops, something went wrong.