You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.log(`Replacing ${count} placeholders with in-loop sync statements took ${Date.now() - startTime} milliseconds.`);
77
+
});
78
+
}
79
+
async function setup(timesToAddText: number = 1) {
80
+
await Word.run(async (context) => {
81
+
console.log("Setup beginning...");
82
+
const body: Word.Body = context.document.body;
83
+
body.clear();
84
+
while (timesToAddText > 0) {
85
+
body.insertParagraph(
86
+
"This defines the roles of {Coordinator}, {Deputy}, {Manager}.",
87
+
Word.InsertLocation.end
88
+
);
89
+
body.insertParagraph(
90
+
"{Coordinator}: Oversees daily operations and ensures projects run smoothly by coordinating between different teams and resources.",
91
+
Word.InsertLocation.end
92
+
);
93
+
body.insertParagraph(
94
+
"{Deputy}: Assists and supports senior management, often stepping in to make decisions or manage tasks in {Manager}'s absence.",
95
+
Word.InsertLocation.end
96
+
);
97
+
body.insertParagraph(
98
+
"{Manager}: Leads the team, setting goals, planning strategies, and making decisions to achieve organizational objectives.",
99
+
Word.InsertLocation.end
100
+
);
101
+
timesToAddText--;
102
+
}
103
+
await context.sync();
104
+
console.log("Setup complete.");
105
+
});
106
+
}
107
+
async function addLotsOfText() {
108
+
// Add the setup text 100 times.
109
+
setup(100);
110
+
}
111
+
// Default helper for invoking an action and handling errors.
112
+
async function tryCatch(callback) {
113
+
try {
114
+
await callback();
115
+
} catch (error) {
116
+
// Note: In a production add-in, you'd want to notify the user through your add-in's UI.
117
+
console.error(error);
118
+
}
119
+
}
120
+
language: typescript
121
+
template:
122
+
content: |-
123
+
<section class="ms-Fabric ms-font-m">
124
+
<p>This sample demonstrates the performance optimization gained from the correlated objects pattern. For more information, see <a href="https://learn.microsoft.com/en-us/office/dev/add-ins/concepts/correlated-objects-pattern">Avoid using the context.sync method in loops</a>.</p>
125
+
</section>
126
+
127
+
<section class="ms-Fabric samples ms-font-m">
128
+
<h3>Setup</h3>
129
+
<p>Use <b>Setup</b> to create a basic text block with some placeholders. Use <b>More text</b> to create a longer text block to better see performance distinctions.</p>
0 commit comments