-
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.
Start converting to classic classes (#677)
* Start converting to classic classes * Finish up conversion and convert TBody
- Loading branch information
1 parent
878194c
commit 90f07d8
Showing
5 changed files
with
194 additions
and
164 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.