-
Notifications
You must be signed in to change notification settings - Fork 2
Fix examples + Copy example button #22
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| // Example cases for the language service sample | ||
| const exampleCases = [ | ||
| { | ||
| id: 'math', | ||
| title: 'Mathematical Expression', | ||
| description: 'Basic math operations with variables', | ||
| expression: '(x + y) * multiplier + sqrt(16)', | ||
| context: { | ||
| x: 10, | ||
| y: 5, | ||
| multiplier: 3 | ||
| } | ||
| }, | ||
| { | ||
| id: 'arrays', | ||
| title: 'Working with Arrays', | ||
| description: 'Array functions like sum, min, max', | ||
| expression: 'sum(numbers) + max(numbers) - min(numbers)', | ||
| context: { | ||
| numbers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], | ||
| values: [15, 25, 35] | ||
| } | ||
| }, | ||
| { | ||
| id: 'objects', | ||
| title: 'Object Manipulation', | ||
| description: 'Access nested object properties', | ||
| expression: 'user.profile.score * level.multiplier + bonus.points', | ||
| context: { | ||
| user: { | ||
| name: "Alice", | ||
| profile: { | ||
| score: 85, | ||
| rank: "Gold" | ||
| } | ||
| }, | ||
| level: { | ||
| current: 5, | ||
| multiplier: 1.5 | ||
| }, | ||
| bonus: { | ||
| points: 100, | ||
| active: true | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| id: 'map-filter', | ||
| title: 'Map and Filter Functions', | ||
| description: 'Transform and filter data with callbacks', | ||
| expression: 'sum(\n map(\n f(x) = x * 2, \n filter(\n f(i) = i > threshold, \n items\n )\n )\n) / length(items)', | ||
| context: { | ||
| items: [1, 2, 3, 4, 5, 6, 7, 8], | ||
| threshold: 3 | ||
| } | ||
| }, | ||
| { | ||
| id: 'complex', | ||
| title: 'Complex Objects', | ||
| description: 'Work with deeply nested data structures', | ||
| expression: 'length(company.departments[0].employees) * company.settings.bonusRate + sum(map(f(d) = d.budget, company.departments))', | ||
| context: { | ||
| company: { | ||
| name: "TechCorp", | ||
| departments: [ | ||
| { | ||
| name: "Engineering", | ||
| budget: 500000, | ||
| employees: ["John", "Jane", "Bob"] | ||
| }, | ||
| { | ||
| name: "Marketing", | ||
| budget: 200000, | ||
| employees: ["Alice", "Carol"] | ||
| } | ||
| ], | ||
| settings: { | ||
| bonusRate: 0.15, | ||
| fiscalYear: 2024 | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| id: 'data-transform', | ||
| title: 'Data Transformation', | ||
| description: 'Flatten nested objects and transform rows', | ||
| expression: "map(f(row) = {_id: row.rowId} + flatten(row.data, ''), $event)", | ||
| context: { | ||
| "$event": [ | ||
| {"rowId": 1, "state": "saved", "data": { "InventoryId": 1256, "Description": "Bal", "Weight": { "Unit": "g", "Amount": 120 } }}, | ||
| {"rowId": 2, "state": "new", "data": { "InventoryId": 2344, "Description": "Basket", "Weight": { "Unit": "g", "Amount": 300 } }}, | ||
| {"rowId": 3, "state": "unchanged", "data": { "InventoryId": 9362, "Description": "Wood", "Weight": { "Unit": "kg", "Amount": 18 } }} | ||
| ] | ||
| } | ||
| } | ||
| ]; |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -143,6 +143,7 @@ <h1 class="text-xl font-bold bg-gradient-to-r from-indigo-600 to-purple-600 dark | |||
| <span>Saved to localStorage</span> | ||||
| </div> | ||||
|
|
||||
| <script src="examples.js"></script> | ||||
|
||||
| <script src="examples.js"></script> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -32,7 +32,7 @@ const server = http.createServer((req, res) => { | |||||
|
|
||||||
| if (urlPath === '/' || urlPath === '/index.html') { | ||||||
| urlPath = 'samples/language-service-sample/index.html'; | ||||||
| } else if (urlPath === '/styles.css' || urlPath === '/app.js') { | ||||||
| } else if (urlPath === '/styles.css' || urlPath === '/app.js' || urlPath === '/examples.js') { | ||||||
|
||||||
| } else if (urlPath === '/styles.css' || urlPath === '/app.js' || urlPath === '/examples.js') { | |
| } else if (urlPath === '/styles.css' || urlPath === '/app.js') { |
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.
exampleCasesis referenced here but no longer defined in this file and there is no other definition in the repo, so this will throw aReferenceErrorat runtime unless a globalexampleCasesis provided (e.g., by the newexamples.js). Either reintroduce the data here or ensureexamples.jsexists, definesexampleCaseson the global scope, and is loaded before this script.