-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The refactor to the reference system attempted to squash/normalize th…
…e difference between a `(mut)` reference (previously – "Invokable" reference, admittedly a very confusing name) and an "accessor" reference. This was a mistake. The Ember usage that necessitated this feature requires that they are distinct. Specifically `{{action (mut this.someProp)}}` is explicitly a distinctly different usage than `{{action this.someProp}}`.
- Loading branch information
1 parent
33bab34
commit 53031fc
Showing
7 changed files
with
61 additions
and
27 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
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
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,25 +1,38 @@ | ||
import type { Reactive, ReactiveFormula } from '@glimmer/interfaces'; | ||
import type { Reactive } from '@glimmer/interfaces'; | ||
|
||
import type { InternalReactive } from './internal/reactive'; | ||
|
||
import { ResultAccessor } from './accessor'; | ||
import { InternalResultAccessor } from './accessor'; | ||
import { unwrapReactive } from './core'; | ||
import { Formula } from './formula'; | ||
import { readInternalReactive, updateInternalReactive } from './internal/operations'; | ||
import { DEEPLY_CONSTANT, READONLY_CELL, REFERENCE } from './internal/reactive'; | ||
import { DEEPLY_CONSTANT, MUTABLE_REF, READONLY_CELL, REFERENCE } from './internal/reactive'; | ||
import { isMutRef, isUpdatableRef } from './predicates'; | ||
|
||
export function toReadonly<T>(reactive: Reactive<T>): ReactiveFormula<T> { | ||
return Formula(() => unwrapReactive(reactive)); | ||
export function toReadonly<T>(reactive: Reactive<T>): Reactive<T> { | ||
if (isMutRef(reactive) || isUpdatableRef(reactive)) { | ||
return Formula(() => unwrapReactive(reactive)); | ||
} else { | ||
return reactive; | ||
This comment has been minimized.
Sorry, something went wrong.
NullVoxPopuli
Contributor
|
||
} | ||
} | ||
|
||
export function toMut<T>(maybeMut: Reactive<T>): Reactive<T> { | ||
const reactive = maybeMut as InternalReactive; | ||
|
||
return ResultAccessor({ | ||
if (isMutRef(maybeMut)) { | ||
return maybeMut; | ||
} | ||
|
||
// TODO probably should assert that maybeMut is updatable | ||
This comment has been minimized.
Sorry, something went wrong. |
||
// Ember already has the same assertion | ||
|
||
return InternalResultAccessor({ | ||
get: () => readInternalReactive(maybeMut as InternalReactive<T>), | ||
set: (value: unknown) => updateInternalReactive(reactive, value), | ||
}); | ||
}, undefined, MUTABLE_REF); | ||
} | ||
|
||
export function isConstant(reactive: Reactive) { | ||
switch (reactive[REFERENCE]) { | ||
case READONLY_CELL: | ||
|
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
needs
pnpm linfix