-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat: add the IVariableMap and IVariableModel interfaces. #8369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gonfunko
merged 2 commits into
RaspberryPiFoundation:rc/v12.0.0
from
gonfunko:variables
Jul 15, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,72 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2024 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import {IVariableModel} from './i_variable_model.js'; | ||
| import {State} from '../serialization/variables.js'; | ||
|
|
||
| /** | ||
| * Variable maps are container objects responsible for storing and managing the | ||
| * set of variables referenced on a workspace. | ||
| * | ||
| * Any of these methods may define invariants about which names and types are | ||
| * legal, and throw if they are not met. | ||
| */ | ||
| export interface IVariableMap<T extends IVariableModel, U extends State> { | ||
| /* Returns the variable corresponding to the given ID, or null if none. */ | ||
| getVariableById(id: string): T | null; | ||
|
|
||
| /** | ||
| * Returns the variable with the given name, or null if not found. If `type` | ||
| * is provided, the variable's type must also match, or null should be | ||
| * returned. | ||
| */ | ||
| getVariable(name: string, type?: string): T | null; | ||
|
|
||
| /* Returns a list of all variables managed by this variable map. */ | ||
| getAllVariables(): T[]; | ||
|
|
||
| /** | ||
| * Returns a list of all of the variables of the given type managed by this | ||
| * variable map. | ||
| */ | ||
| getVariablesOfType(type: string): T[]; | ||
|
|
||
| /** | ||
| * Returns a list of the set of types of the variables managed by this | ||
| * variable map. | ||
| */ | ||
| getTypes(): string[]; | ||
|
|
||
| /** | ||
| * Creates a new variable with the given name. If ID is not specified, the | ||
| * variable map should create one. Returns the new variable. | ||
| */ | ||
| createVariable(name: string, id?: string, type?: string | null): T; | ||
|
|
||
| /** | ||
| * Changes the name of the given variable to the name provided and returns the | ||
| * renamed variable. | ||
| */ | ||
| renameVariable(variable: T, newName: string): T; | ||
|
|
||
| /* Changes the type of the given variable and returns it. */ | ||
| changeVariableType(variable: T, newType: string): T; | ||
|
|
||
| /* Deletes the given variable. */ | ||
| deleteVariable(variable: T): void; | ||
|
|
||
| /* Removes all variables from this variable map. */ | ||
| clear(): void; | ||
|
|
||
| /* Returns an object representing the serialized state of the variable. */ | ||
| saveVariable(variable: T): U; | ||
|
|
||
| /** | ||
| * Creates a variable in this variable map corresponding to the given state | ||
| * (produced by a call to `saveVariable`). | ||
| */ | ||
| loadVariable(state: U): T; | ||
| } | ||
This file contains hidden or 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,26 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2024 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /* Representation of a variable. */ | ||
| export interface IVariableModel { | ||
| /* Returns the unique ID of this variable. */ | ||
| getId(): string; | ||
|
|
||
| /* Returns the user-visible name of this variable. */ | ||
| getName(): string; | ||
|
|
||
| /** | ||
| * Returns the type of the variable like 'int' or 'string'. Does not need to be | ||
| * unique. This will default to '' which is a specific type. | ||
| */ | ||
| getType(): string; | ||
|
|
||
| /* Sets the user-visible name of this variable. */ | ||
| setName(name: string): this; | ||
|
|
||
| /* Sets the type of this variable. */ | ||
| setType(type: string): this; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copyright statement plox. Here and in the other file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!