Angular / Intermediate / Lesson 14
Pure pipes and value identity
Create a pure display transformation and understand how immutable inputs affect when Angular recalculates it.
On this page
Lesson goals
- Implement and import a custom pipe.
- Explain pure pipe input identity.
- Test empty and changed values.
- Implement and import a pure presentation pipe with explicit input and empty-value policies.
- Explain identity-sensitive updates and verify transform behavior separately from hosted rendering.
Choose a display transformation
A pipe transforms a value for presentation in a template. It is useful for a small deterministic formatting rule shared by several views; it should not hide a network request or mutate the source data. First decide what the transformation returns for an empty input and whether a built-in locale-aware pipe already meets the requirement. This example joins names rather than translating them.
Define a pure pipe
This pipe implements PipeTransform and returns a string without changing its array. Angular pipes are pure by default: Angular can skip recalculation while input arguments are unchanged. The empty case has explicit output. For user-facing production text, replace the example’s English message with the application’s localization strategy and test the relevant locales.
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({ name: "joinNames", standalone: true })
export class JoinNamesPipe implements PipeTransform {
transform(names: readonly string[]): string {
return names.length ? names.join(", ") : "No names";
}
}
An empty array produces No names.
The transformation joins the supplied names or returns a clear empty value without modifying the input.
Use and update the input
The standalone component imports the pipe in its own template scope. Its add handler replaces the array with a new one, so the pure pipe receives a changed reference. The example assumes the Angular host supplies standard bootstrap and build configuration. Clicking repeatedly appends the same sample name; a real application should define its own duplicate policy.
import { Component } from "@angular/core";
import { JoinNamesPipe } from "./join-names.pipe";
@Component({
selector: "app-names", standalone: true, imports: [JoinNamesPipe],
template: `<p>{{ names | joinNames }}</p><button (click)="add()">Add</button>`
})
export class NamesComponent {
names: readonly string[] = ["Ada"];
add() { this.names = [...this.names, "Lin"]; }
}
Initially Ada; after one click Ada, Lin.
The button publishes a new array; the template renders the transformed names.
Understand identity and cost
Mutating an existing array in place does not change its reference, so a pure pipe may continue displaying its previous result. Publish a replacement when the data changes and retain the old value when it does not. An impure pipe can run on every change-detection cycle and may be expensive; measure and justify it instead of using it to conceal unclear state ownership.
Verify the contract
Test the transform with an empty list, one name and multiple names, and confirm it does not alter its input. Render the component, add a name and assert the visible text. Also test a parent that supplies a replacement array. Keep tests focused on the user-visible transformation rather than assuming a particular number of internal pipe calls.
Choose a deterministic presentation transformation
An Angular pipe transforms a value for presentation in a template. A small formatting rule used by several views may belong in a pipe when its inputs, output, empty case, and localization policy are clear. First consider whether a built-in locale-aware pipe already meets the requirement. A pipe should not fetch data, mutate its input, or hide an authorization decision. Data loading belongs to a service or owner with an explicit lifecycle; the pipe receives the resulting value and produces a display result.
A standalone pipe must be available in the imports of the component whose template uses it. The pipe name in the template is the name declared in @Pipe metadata, not necessarily its TypeScript class name. Test the transform directly with synthetic values, then compile the consumer and inspect the rendered result. A direct method call does not prove the template imported or invoked the pipe. The fragments below target Angular 20.3.0 and are non-runnable here; no Angular compilation or browser execution is claimed.
Understand pure input identity
Angular pipes are pure by default. A pure pipe can be invoked when a primitive input or an object reference changes; mutating the contents of an existing array while keeping its reference can leave the previous transformed display in place. Publish a replacement array for a meaningful update and preserve the old array. For nested objects, copy the changed path as well as the outer collection. Verify the actual output and the unchanged prior data; a new reference by itself does not prove the domain result is correct.
Pipe arguments also participate in the transformation contract. A changed separator, locale, or other argument can require a new result even if the primary collection is unchanged. Do not mutate an input inside transform or rely on the number of internal calls as a user contract. For a documented no-op, retaining the same value may be appropriate. An impure pipe can run frequently during change detection and should not be used simply to conceal in-place mutation or unclear state ownership. Measure and justify its cost if a legitimate use requires one.
Define empty, null, and localization policies
A display transformation needs explicit behavior for empty arrays, missing values, and invalid inputs. A join pipe might return “No names” for an empty list and join two names with a comma for populated data. In a real multilingual product, that English fallback and separator require a localization policy; a simple join does not translate names or implement locale-aware grammar. Decide whether null is permitted by the pipe’s type and template contract rather than adding a fallback that silently hides bad data. Test boundary cases for each supported locale.
A formatting result is not a trusted validation or security decision. If the source is an HTTP response, validate its shape and domain rules before passing it to presentation. Do not use a pipe to authorize a record or hide a private field already delivered to the browser. Returning a formatted value should not change the source array or its elements. A pure calculation can be tested independently, but the user-facing contract also includes the actual text, accessible context, and any control used to update the data.
Publish changed values at the owner
The component or service that owns a collection is responsible for publishing changes. For an Add button, replace names with [...names, newName] rather than pushing into the existing array when a pure pipe depends on its identity. If duplicates are forbidden, enforce that separately; a new reference can still contain an invalid duplicate. A parent supplying a replacement input should follow the same rule and retain stable domain ids when the view is a dynamic list. A pipe formats data; it does not create a state-management or persistence policy.
Keep expensive work and external effects out of frequently evaluated display paths. A pure pipe can avoid some recalculation when arguments are unchanged, but the application must remain correct if it runs again. An impure pipe may run during every relevant change-detection cycle, so measure representative interactions and understand memory and CPU cost before choosing it. If a costly computation dominates, consider the data model or a documented caching strategy; do not promise a speedup from a tiny teaching fixture.
Test transform, identity, and rendered behavior
Test the pure transform with empty, one-item, and multiple-item inputs and any documented argument changes. Confirm the input array remains unchanged. Then compile a standalone consumer with the pipe in its imports, render it, use the actual Add control, and verify the displayed text after a replacement update. Include a parent-supplied new reference and a no-op case where appropriate. A direct transform test proves its returned string, not template import, change detection, keyboard behavior, or localization in a browser.
Test a deliberately mutated input as a diagnostic case, but repair the owner rather than forcing an impure pipe without evidence. Preserve all required rows and error states in performance comparisons, and record the Angular version, locale, input identity, and host. Test server validation and authorization separately if data is remote. The examples below are contextual Angular 20.3.0 pipe or data fixtures and are non-runnable here; their results are reasoned predictions, not claims of compilation, profiling, or browser execution.
20 worked examples
1. Empty count label
Problem: Return a clear label for a zero-item collection.
- The input count is zero.
- The explicit zero branch supplies the documented empty label.
function itemCountLabel(count: number): string { return count === 0 ? "No items" : `${count} items`; }
const result = itemCountLabel(0);
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: result is No items.
Why this result follows: The input count is zero. The explicit zero branch supplies the documented empty label.
2. Single initial
Problem: Format an initial from one supplied name without changing the source.
- The calculation trims the surrounding spaces before reading the first character.
- It returns an uppercase display value without mutating the input string.
function initial(name: string): string { return name.trim().charAt(0).toUpperCase(); }
const result = initial(" ada ");
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: result is A.
Why this result follows: The calculation trims the surrounding spaces before reading the first character. It returns an uppercase display value without mutating the input string.
3. Changed separator
Problem: Use a supplied delimiter as part of a pure transformation contract.
- The function receives two names and the explicit separator.
- join places that separator between the entries without mutating them.
function joinWith(names: readonly string[], separator: string): string { return names.join(separator); }
const result = joinWith(["Ada", "Lin"], " / ");
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: result is Ada / Lin.
Why this result follows: The function receives two names and the explicit separator. join places that separator between the entries without mutating them.
4. Standalone pipe
Problem: Declare a reusable pure display pipe for a title prefix.
- The pipe names a deterministic display transformation.
- It builds a string from its input without changing external state.
@Pipe({ name: "courseLabel", standalone: true })
class CourseLabelPipe implements PipeTransform {
transform(title: string): string { return `Course: ${title}`; }
}
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: The transform for Forms returns Course: Forms.
Why this result follows: The pipe names a deterministic display transformation. It builds a string from its input without changing external state.
5. Import the pipe
Problem: Make a standalone pipe available to its consuming component template.
- The component imports the standalone pipe it uses.
- The template pipe name matches the declared courseLabel name.
@Component({ selector: "app-course", standalone: true, imports: [CourseLabelPipe], template: `<p>{{ title | courseLabel }}</p>` })
class Course { title = "Forms"; }
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: In a configured host, the paragraph reads Course: Forms.
Why this result follows: The component imports the standalone pipe it uses. The template pipe name matches the declared courseLabel name.
6. Missing pipe import
Problem: Diagnose a consumer that uses a standalone pipe without listing it.
- The template uses the courseLabel pipe name.
- The shown standalone imports list is empty.
@Component({ selector: "app-course", standalone: true, imports: [], template: `<p>{{ title | courseLabel }}</p>` })
class Course { title = "Forms"; }
// CourseLabelPipe exists separately.
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: The consumer has not supplied CourseLabelPipe in its template imports.
Why this result follows: The template uses the courseLabel pipe name. The shown standalone imports list is empty.
7. Replace an array
Problem: Publish an added name using a new array reference.
- Spread creates a replacement array.
- The previous input is not changed by appending Lin.
const old = ["Ada"];
const next = [...old, "Lin"];
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: next is ["Ada", "Lin"] while old remains ["Ada"].
Why this result follows: Spread creates a replacement array. The previous input is not changed by appending Lin.
8. Mutation risk
Problem: Identify why an in-place push may leave a pure-pipe display stale.
- push mutates the existing array rather than replacing it.
- A pure pipe observing only the unchanged array reference may not recalculate.
const names = ["Ada"];
const previous = names;
names.push("Lin");
const same = Object.is(previous, names);
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: same is true even though the array contents now include Lin.
Why this result follows: push mutates the existing array rather than replacing it. A pure pipe observing only the unchanged array reference may not recalculate.
9. Do not mutate input
Problem: Use a nonmutating join transformation on a readonly array.
- join returns a string rather than changing the source array.
- The readonly input documents that the transform should not mutate it.
const names: readonly string[] = ["Ada", "Lin"];
const result = names.join(", ");
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: result is Ada, Lin and names still contains Ada then Lin.
Why this result follows: join returns a string rather than changing the source array. The readonly input documents that the transform should not mutate it.
10. Changed argument
Problem: Treat a changed separator as an input to the display result.
- The names are the same in both calculations.
- The separator argument changes the expected presentation.
const names = ["Ada", "Lin"];
const comma = names.join(", ");
const slash = names.join(" / ");
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: comma is Ada, Lin and slash is Ada / Lin.
Why this result follows: The names are the same in both calculations. The separator argument changes the expected presentation.
11. Null policy
Problem: Reject an unsupported null input rather than hiding it as an empty list.
- The explicit null branch is evaluated first.
- A missing value is distinct from a valid empty array in this contract.
function format(names: readonly string[] | null): string {
if (names === null) return "Data unavailable";
return names.length ? names.join(", ") : "No names";
}
const result = format(null);
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: result is Data unavailable.
Why this result follows: The explicit null branch is evaluated first. A missing value is distinct from a valid empty array in this contract.
12. Nested replacement
Problem: Copy a changed nested item before publishing a collection.
- The map creates a new array and a replacement matching item.
- The changed nested profile is copied instead of mutating the prior snapshot.
const old = [{ id: "a", profile: { name: "Ada" } }];
const next = old.map(item => item.id === "a" ? { ...item, profile: { ...item.profile, name: "Adele" } } : item);
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: next contains Adele while old still contains Ada.
Why this result follows: The map creates a new array and a replacement matching item. The changed nested profile is copied instead of mutating the prior snapshot.
13. Duplicate policy
Problem: Keep a duplicate out separately from the formatting rule.
- The owner checks whether the candidate already exists.
- The pipe need not invent or enforce that domain rule.
const names = ["Ada"];
const candidate = "Ada";
const next = names.includes(candidate) ? names : [...names, candidate];
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: next remains ["Ada"] under this no-duplicate policy.
Why this result follows: The owner checks whether the candidate already exists. The pipe need not invent or enforce that domain rule.
14. Localized fallback fixture
Problem: Make the empty-message language an explicit input to a simple formatter.
- The empty message is supplied explicitly rather than inferred from a locale.
- A real localization policy must supply and test the appropriate translated text.
function format(names: readonly string[], emptyText: string): string { return names.length ? names.join(", ") : emptyText; }
const result = format([], "No names");
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: result is No names for the supplied English fallback.
Why this result follows: The empty message is supplied explicitly rather than inferred from a locale. A real localization policy must supply and test the appropriate translated text.
15. No network in transform
Problem: Keep a pure display function independent of data fetching.
- The function calculates only from its argument.
- A service or owner must separately load any remote title.
function label(title: string): string { return `Course: ${title}`; }
const result = label("Forms");
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: result is Course: Forms with no network operation.
Why this result follows: The function calculates only from its argument. A service or owner must separately load any remote title.
16. Impure cost plan
Problem: Record a measurement question before choosing an impure pipe.
- An impure pipe can run frequently during change detection.
- A representative measurement is needed before claiming acceptable cost or improvement.
const plan = { interaction: "update a large list", concern: "frequent impure transform", measured: false };
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: The fixture records a performance question and no measured result.
Why this result follows: An impure pipe can run frequently during change detection. A representative measurement is needed before claiming acceptable cost or improvement.
17. Parent replacement
Problem: Supply a new collection reference to a pure-pipe consumer.
- The parent creates a new array for the meaningful update.
- The changed reference can be supplied to the child’s pipe input.
const parentNames = ["Ada"];
const updatedNames = [...parentNames, "Lin"];
const changed = !Object.is(parentNames, updatedNames);
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: changed is true and updatedNames contains Ada and Lin.
Why this result follows: The parent creates a new array for the meaningful update. The changed reference can be supplied to the child’s pipe input.
18. Stable unchanged argument
Problem: Keep a primitive formatting input unchanged when a discount is not applicable.
- The fixture specifies that no discount applies to the order.
- The owner retains the existing primitive rate instead of inventing a change.
const rate = 0;
const eligible = false;
const nextRate = eligible ? 0.1 : rate;
const same = Object.is(rate, nextRate);
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: nextRate is 0 and Object.is(rate, nextRate) is true.
Why this result follows: The fixture specifies that no discount applies to the order. The owner retains the existing primitive rate instead of inventing a change.
19. Model versus view
Problem: Separate a direct transform result from a component rendering claim.
- A transform can be invoked independently of Angular’s view.
- The consumer import and rendered interaction require another test.
const evidence = { directResult: "Ada, Lin", templateCompiled: false, browserRendered: false };
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: The fixture records a string result but no template or browser evidence.
Why this result follows: A transform can be invoked independently of Angular’s view. The consumer import and rendered interaction require another test.
20. Performance equivalence
Problem: Reject a faster formatting comparison that removes required entries.
- It omits one hundred names and hides errors.
- A smaller task is not evidence of a faithful performance improvement.
const before = { names: 1000, errorsVisible: true };
const after = { names: 900, errorsVisible: false };
Trace the stated transformation or identity; no compilation or profiling is claimed.
Expected result: The after fixture does not preserve the same required outcome.
Why this result follows: It omits one hundred names and hides errors. A smaller task is not evidence of a faithful performance improvement.
Common errors and fixes
The pipe name is unknown in the template.
- Why it happens
- The standalone component did not import the pipe.
- How to fix it
- Add the pipe to the owning component imports.
- Prevent it next time
- Compile a minimal consumer template.
The displayed names remain stale.
- Why it happens
- The existing input array was mutated without changing its reference.
- How to fix it
- Publish a replacement array.
- Prevent it next time
- Test the data owner’s update path.
Formatting slows repeated checks.
- Why it happens
- An expensive impure pipe runs frequently.
- How to fix it
- Use a pure transformation and stable inputs when suitable.
- Prevent it next time
- Measure representative interactions before optimizing.
20 practice exercises
1. What happens if an item is pushed into the existing input array?
Show hint
Compare the array reference before and after push.
Show worked solution
Its reference stays the same, so a pure pipe may not run again. Publish a new array and verify the resulting visible names.
push mutates the existing array and keeps the same reference, so the pure pipe may continue to display its previous result. Publish a replacement array at the owner and verify the rendered names after change detection; also confirm the old snapshot was not mutated.
Check your solution
- A replacement array is used for the meaningful update.
- The actual displayed names update in a component host.
2. Why should a pipe avoid fetching data?
Show hint
A display transformation should be predictable from its inputs.
Show worked solution
A display transformation should return a predictable result for its inputs. Fetch data at an appropriate owner and pass the resulting value to the presentation layer.
Fetch data in an appropriate service or owner with explicit error and lifecycle handling, then pass the resulting value to the pipe. A pipe that performs a request can repeat external work during evaluation and mixes transport with presentation.
Check your solution
- The pipe performs no network request.
- The data owner handles loading and failure.
3. Design a standalone pipe that prefixes a course title and import it into a consuming component.
Show hint
Declare a pipe name and the consumer’s template dependency.
Show worked solution
Implement a pure PipeTransform returning `Course: ${title}`, mark the pipe standalone, and include it in the consuming component imports. For Forms the intended text is Course: Forms. Test the transform directly and compile the real consumer template separately.
Check your solution
- The transform returns Course: Forms.
- The consumer imports the standalone pipe.
4. A template uses courseLabel but the standalone owner does not import its pipe. Diagnose the failure.
Show hint
Template scope is determined at the consuming component.
Show worked solution
Add the intended CourseLabelPipe to the owner’s imports and verify that the @Pipe name matches courseLabel. Compile and render the actual consumer. A direct transform test or a TypeScript import alone does not establish that the template can use the pipe.
Check your solution
- The owning component imports the pipe.
- The template name matches the pipe metadata.
5. A pure join transform receives an empty array. Define a clear output and test its limit.
Show hint
Document the empty case rather than leaving a blank region.
Show worked solution
Under the teaching contract, return No names for an empty array and test that result directly. In a multilingual product, provide a localized fallback and appropriate formatting policy instead of assuming the English string is universal. Verify the actual template separately.
Check your solution
- The empty input has the documented result.
- Localization requirements are explicit.
6. A names array changes from ["Ada"] to include "Lin". Publish a replacement for a pure pipe.
Show hint
Use a new array rather than mutating the existing reference.
Show worked solution
Set names = [...names, "Lin"] at the data owner. The next array contains Ada and Lin while the old array remains ["Ada"]. In a configured consumer, verify that the displayed transform updates after change detection and that the Add control remains accessible.
Check your solution
- The new reference contains both names.
- The previous array remains unchanged.
7. A component pushes Lin into the existing array used by a pure pipe. Explain the stale-display risk.
Show hint
The array reference has not changed.
Show worked solution
push mutates the original array, so the pure pipe may not be invoked again for the unchanged reference. Replace the array at its owner and verify the rendered names. Also check that the previous snapshot was not mutated; an impure pipe is not the first repair.
Check your solution
- The owner publishes a replacement array.
- The displayed names are checked after the update.
8. A pipe receives the same names but its separator changes from comma to slash. Predict the display.
Show hint
The separator is another transformation input.
Show worked solution
For ["Ada", "Lin"], the comma version is Ada, Lin and the slash version is Ada / Lin. Include and test the separator argument in the template contract. Preserve the source array and avoid assuming only the primary array controls the output.
Check your solution
- The comma output is Ada, Lin.
- The slash output is Ada / Lin.
9. A pure pipe sorts its input array in place. Repair the transformation.
Show hint
Copy before invoking the mutating sort method.
Show worked solution
Use [...names].sort() or another nonmutating strategy and return the formatted result from the copy. The old array must retain its original order even if Angular reevaluates the pipe. Test both the output order and preservation of the input snapshot.
Check your solution
- The displayed order follows the copied sort.
- The original array remains unchanged.
10. A nested profile name changes inside an array. Explain why copying only the outer array is insufficient.
Show hint
The nested object can remain shared with the prior snapshot.
Show worked solution
Create a new array, a replacement matching item, and a replacement profile object for the changed name. Verify the old nested name remains unchanged and the new value is correct. A shallow outer copy followed by mutation still changes what earlier references observe.
Check your solution
- The changed path has new objects.
- The old nested profile remains unchanged.
11. A parent sends the same mutable array to two consumers. Define a safer update and test.
Show hint
The owner should publish a replacement without changing prior inputs.
Show worked solution
Create a new array at the parent and pass it to the consumers for a meaningful update. Test that both receive the intended current data while the previous array remains intact. Keep any independent consumer state and domain duplicate policy explicit.
Check your solution
- The parent publishes a new reference.
- The old shared array is unchanged.
12. A duplicate name is not allowed. Explain why a new array alone does not enforce the rule.
Show hint
Immutability and domain validity are separate.
Show worked solution
Check the candidate at the data owner before appending; under a no-duplicate policy, adding Ada to ["Ada"] can return the existing value. Test both the no-op and a distinct valid addition. The pipe should format the accepted collection rather than silently enforce ownership rules.
Check your solution
- The duplicate policy is tested.
- The pipe formats the owner’s accepted data.
13. A pipe receives null although its contract accepts only an array. Define a deliberate response.
Show hint
Do not silently equate missing data with a valid empty list.
Show worked solution
Either reject null at the data boundary or explicitly extend the pipe contract with a distinct unavailable result. Test null and [] separately. Avoid hiding a malformed or loading state behind No names unless that is the documented product meaning.
Check your solution
- Null and an empty array have explicit meanings.
- The component does not assume invalid data is valid empty success.
14. A formatting pipe starts a network request on every transform. Explain the proper separation.
Show hint
A presentation transformation should be deterministic and side-effect free.
Show worked solution
Load data in a service or owner with explicit request, cancellation, error, and authorization responsibilities, then pass the available value to the pipe. Keep transform pure so repeated evaluation does not duplicate requests. Test transport and display at their own boundaries.
Check your solution
- The pipe performs no network operation.
- The data owner handles the request lifecycle.
15. A developer makes a pipe impure to notice in-place mutations. Explain the tradeoff and first investigation.
Show hint
An impure pipe may run frequently and can hide unclear ownership.
Show worked solution
First repair the owner to publish immutable replacements and test the visible result. Use an impure pipe only for a justified contract after measuring representative change-detection cost. Do not assume it is free or that it repairs domain validation.
Check your solution
- The owner’s update path is reviewed first.
- Any impure choice is measured and justified.
16. A pipe displays English "No names" in an Arabic interface. Define a localization review.
Show hint
A hard-coded teaching fallback is not a complete multilingual policy.
Show worked solution
Supply an appropriate localized empty message and consider locale-aware separators or grammar under the product’s translation system. Test empty and populated outputs in the supported locales. Do not assume a simple comma join translates names or meets every language’s conventions.
Check your solution
- The empty message is localized.
- The formatting policy is tested for supported locales.
17. A direct pipe transform test passes but the screen is blank. Identify further evidence needed.
Show hint
The template and host are separate from the method.
Show worked solution
Compile the standalone consumer with the pipe imported, render it with known input, and inspect the visible output after the relevant update. Check the pipe name and any errors. The direct test proves only the returned value, not template scope or browser behavior.
Check your solution
- The actual consumer imports and uses the pipe.
- The rendered text is verified in a host.
18. A faster benchmark drops error rows while formatting a list. Evaluate the optimization claim.
Show hint
The compared tasks must preserve required behavior.
Show worked solution
Reject the speedup claim until the required rows and errors remain present in both versions. Repeat the same data and interaction under comparable build and device conditions, recording memory and accessibility costs. Less work for a different result is not a faithful optimization.
Check your solution
- Required rows and errors remain visible.
- The performance comparison uses equivalent behavior.
19. A pipe formats a private record that arrived from HTTP. Where do validation and authorization belong?
Show hint
Presentation does not establish trust in the delivered data.
Show worked solution
Validate the response shape and domain constraints at the data boundary and have the trusted server authorize the specific user and record before delivery. Pass only permitted data to the pipe. A display transform or hidden field cannot protect private data already sent to the browser.
Check your solution
- The response is validated before presentation.
- The server enforces resource-specific access.
20. Design a pipe verification plan covering empty, changed argument, immutable update, and rendered interaction.
Show hint
Combine pure-transform and hosted-component evidence.
Show worked solution
Test empty, one, and multiple items plus a changed separator while confirming the input remains unchanged. Compile the consumer with its pipe import, activate Add, and assert the updated displayed text after a replacement array. Check accessibility and locale behavior where required, and report what actually ran.
Check your solution
- Direct transformation and input preservation are checked.
- The hosted update and relevant accessibility or locale contract are verified.
Key takeaways
- Pipes transform values for display.
- Pure pipes respond to changed primitive values or object references.
- Test empty inputs and replacement updates.
- Pure pipes format values; they do not own fetching, authorization, or persistence.
- Publish replacement references for meaningful object or array changes.
- Test output, input preservation, locale, and actual consumer wiring.