Automatically maintaining thousands of code demos across multiple framework variations

Rate this content
Bookmark

At AG Grid, we maintain thousands of code demos, with the same demo in Angular, React, Vue, and Vanilla JS. Additionally, each framework has different variations covering JavaScript, TypeScript, Modules, Packages, Hooks, Classes, Vue 2, and Vue 3. How do we do it? We automate. This session will explain how we start with a single TypeScript version and automatically convert it to every combination we need and finally use Cypress to test the converted example.

This talk has been presented at JSNation 2022, check out the latest edition of this JavaScript Conference.

FAQ

AG Grid's primary goal is to make the best JavaScript data grid in the world.

AG Grid provides live code demos for every feature to show users what the grid can do and to display the code powering each demo.

AG Grid currently maintains about 8,000 code demos.

AG Grid supports JavaScript, TypeScript, Angular, React, Vue 2, and Vue 3. It can be used with hooks and classes.

TypeScript is used as the starting point because it is needed for Angular and React with TSX examples. For JavaScript examples, types are stripped out from TypeScript.

AG Grid categorizes its code examples into static config, callbacks, and external events to apply framework-specific converters to each section.

An abstract syntax tree (AST) is a tree representation of the abstract syntactic structure of source code. It is used to programmatically categorize code examples.

AG Grid validates the generated code examples by using TypeScript for validation, Cypress for error checking and visual regressions, and git diff to ensure no mistakes.

The benefit of AG Grid's approach is that it allows for updating all framework examples in one place, reducing maintenance effort and freeing up developers to work on new features.

A useful tool for visualizing abstract syntax trees is astexplorer.net, where you can drop your code to see the AST representation.

Stephen Cooper
Stephen Cooper
7 min
16 Jun, 2022

Comments

Sign in or register to post your comment.
Video Summary and Transcription
The talk focuses on creating the best JavaScript data grid by categorizing code using abstract syntax trees. Code files are represented as tree structures, allowing for the extraction of different sections. Framework-specific converters generate code examples for Angular, React, and Vue. TypeScript validation and testing ensure code quality and easy updates for framework examples.

1. Introduction to Code Demos and Categorization

Short description:

Our aim is to make the best JavaScript data grid in the world. We have about 500 demos and 8,000 demos in total. We want to write a single example in TypeScript and categorize the code using abstract syntax trees.

Can I ask you a question before I start? How many of you would be happy at your job if they asked you to maintain thousands of code demos? For me, you are happy. There's probably a good job for you in writing docs. But for me, you know, that's not what I want to do. And that's a situation I found ourselves in at aggrid.

Now our aim is to make the best JavaScript data grid in the world. But we understand, as Rich was talking about earlier, that our grid is only going to be as good as what our users can do with it, and the way we can show them what they can do is via our docs. So we are determined for every feature that we have to have a live code demo. So you'll see what the grid does. And you'll also see the code that is powering that demo.

So if we just start adding in all these examples for our features, we've actually got up to about 500 demos now, and you think that's bad enough. Wait till you realize the AG grid is agnostic. So we support JavaScript, TypeScript, Angular, React, you can use hooks and classes, you can write it in view two, view three. And we want you, when you're using our docs, to be able to see the code in the framework that you're using. So you times all these numbers together, and we end up with about 8,000 demos. So there's no way, even if you do want to do it, that you're going to be able to keep up and not make mistakes with copy and paste. And it's just going to be quite boring, to be honest.

So in an ideal world, what we want to do is write a single example, and we're going to do this in TypeScript, because for Angular, we need types. If you want React with TSX, you need types. For our JavaScript example, we just strip the types out and we're done. And then we can use that as a starting point for our view and React with just plain JavaScript. Now, the first step to be able to achieve this is to categorize your code. So here we've got some example AG grid code. We've got some static config. We've got a callback and also an external event. And the reason we need to categorize this is so that we can apply framework-specific converters to each of these specific areas. Because we know that Angular uses different syntax to react. And it's different depending on what you're trying to achieve. But then the challenge and the question is, how do we programmatically categorize our code example? And that's where abstract syntax trees come in. Because we can represent any piece of code as a tree. So, for example, the highlighted function here is size to fit.

2. Generating and Maintaining Framework Examples

Short description:

We represent code files as a tree structure using abstract syntax trees. By parsing the code with TypeScript, we can extract different sections like properties, methods, and event handlers. Framework-specific converters allow us to generate code examples for Angular, React, and Vue. We validate the code with TypeScript and perform testing to ensure quality. This approach enables us to update framework examples easily and provides users with code that matches their chosen framework.

And that's represented as a function definition with a property of name, parameters, and the body. And any code file that you've got, you can break it down and represent it in this tree structure.

So, for example, if you're using type script to parse it, you give it the source text of the example and it will give you this AST. And then we're gonna traverse this tree and use pattern matches to pull out all of these different sections. So, we'll find what's a property, what's an instant method, and what's an event handler.

So, this is an example of what one of these pattern matches might look like. So, we've got... Is this a function call? So, we run through all the nodes in the tree, and if it's a function call, then we pull it out into this external event handlers where we've got the name, the parameters, and the body. So, we build up this memory model of what the code example actually looks like. And then we use our framework-specific converters. So, here we can see Angular and Vue. You've got the different syntax for trying to achieve a similar thing. And so, we use these framework-specific converters against each category. And once you've done that, you can spit that code out into a base template, and you find you've got your Angular, React, and Vue examples.

And we have only written the TypeScript one along with these converters. Just to make sure we haven't made a mistake, we validate it with TypeScript. We hit every single one of these examples with Cypress to make sure there's no errors, a bit of snapshotting for visual regressions. And if we're feeling really keen and careful, we can git diff the entire repo to make sure we haven't done anything silly. And the result for us is that we're able to update all our framework examples in one place. For example, we added support for React and TypeScript, and it only took a day, but there's 500 examples there. If we want to add a new framework support, we'll just add one converter. And we're happy developers because we're not maintaining all of these examples, and there's more time for us to work on features. And I believe our users are happier because they can go to our docs, say what framework they're using, what variation they're using, and they get to see the code that matches that to copy and paste into their application.

So for you as takeaways, I want you to realize this point, that we can use TypeScript abstract syntax trees to generate and reason about our code. And a great way to get started with this is astexplorer.net. Just drop your code into that, and it will show you what the abstract syntax tree looks like. And, finally, don't manually maintain something that you can generate. If you do take inspiration from this work, I'd love to hear what you end up building with it.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Levelling up Monorepos with npm Workspaces
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Levelling up Monorepos with npm Workspaces
Top Content
NPM workspaces help manage multiple nested packages within a single top-level package, improving since the release of NPM CLI 7.0. You can easily add dependencies to workspaces and handle duplications. Running scripts and orchestration in a monorepo is made easier with NPM workspaces. The npm pkg command is useful for setting and retrieving keys and values from package.json files. NPM workspaces offer benefits compared to Lerna and future plans include better workspace linking and adding missing features.
A Framework for Managing Technical Debt
TechLead Conference 2023TechLead Conference 2023
35 min
A Framework for Managing Technical Debt
Top Content
Today's Talk discusses the importance of managing technical debt through refactoring practices, prioritization, and planning. Successful refactoring requires establishing guidelines, maintaining an inventory, and implementing a process. Celebrating success and ensuring resilience are key to building a strong refactoring culture. Visibility, support, and transparent communication are crucial for addressing technical debt effectively. The team's responsibilities, operating style, and availability should be transparent to product managers.
Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
Watch video: Debugging JS
Debugging JavaScript is a crucial skill that is often overlooked in the industry. It is important to understand the problem, reproduce the issue, and identify the root cause. Having a variety of debugging tools and techniques, such as console methods and graphical debuggers, is beneficial. Replay is a time-traveling debugger for JavaScript that allows users to record and inspect bugs. It works with Redux, plain React, and even minified code with the help of source maps.
Building a Voice-Enabled AI Assistant With Javascript
JSNation 2023JSNation 2023
21 min
Building a Voice-Enabled AI Assistant With Javascript
Top Content
This Talk discusses building a voice-activated AI assistant using web APIs and JavaScript. It covers using the Web Speech API for speech recognition and the speech synthesis API for text to speech. The speaker demonstrates how to communicate with the Open AI API and handle the response. The Talk also explores enabling speech recognition and addressing the user. The speaker concludes by mentioning the possibility of creating a product out of the project and using Tauri for native desktop-like experiences.
A Practical Guide for Migrating to Server Components
React Advanced 2023React Advanced 2023
28 min
A Practical Guide for Migrating to Server Components
Top Content
Watch video: A Practical Guide for Migrating to Server Components
React query version five is live and we'll be discussing the migration process to server components using Next.js and React Query. The process involves planning, preparing, and setting up server components, migrating pages, adding layouts, and moving components to the server. We'll also explore the benefits of server components such as reducing JavaScript shipping, enabling powerful caching, and leveraging the features of the app router. Additionally, we'll cover topics like handling authentication, rendering in server components, and the impact on server load and costs.
Power Fixing React Performance Woes
React Advanced 2023React Advanced 2023
22 min
Power Fixing React Performance Woes
Top Content
Watch video: Power Fixing React Performance Woes
This Talk discusses various strategies to improve React performance, including lazy loading iframes, analyzing and optimizing bundles, fixing barrel exports and tree shaking, removing dead code, and caching expensive computations. The speaker shares their experience in identifying and addressing performance issues in a real-world application. They also highlight the importance of regularly auditing webpack and bundle analyzers, using tools like Knip to find unused code, and contributing improvements to open source libraries.

Workshops on related topic

Build Modern Applications Using GraphQL and Javascript
Node Congress 2024Node Congress 2024
152 min
Build Modern Applications Using GraphQL and Javascript
Featured Workshop
Emanuel Scirlet
Miguel Henriques
2 authors
Come and learn how you can supercharge your modern and secure applications using GraphQL and Javascript. In this workshop we will build a GraphQL API and we will demonstrate the benefits of the query language for APIs and what use cases that are fit for it. Basic Javascript knowledge required.
Building a Shopify App with React & Node
React Summit Remote Edition 2021React Summit Remote Edition 2021
87 min
Building a Shopify App with React & Node
Top Content
WorkshopFree
Jennifer Gray
Hanna Chen
2 authors
Shopify merchants have a diverse set of needs, and developers have a unique opportunity to meet those needs building apps. Building an app can be tough work but Shopify has created a set of tools and resources to help you build out a seamless app experience as quickly as possible. Get hands on experience building an embedded Shopify app using the Shopify App CLI, Polaris and Shopify App Bridge.We’ll show you how to create an app that accesses information from a development store and can run in your local environment.
Deploying React Native Apps in the Cloud
React Summit 2023React Summit 2023
88 min
Deploying React Native Apps in the Cloud
WorkshopFree
Cecelia Martinez
Cecelia Martinez
Deploying React Native apps manually on a local machine can be complex. The differences between Android and iOS require developers to use specific tools and processes for each platform, including hardware requirements for iOS. Manual deployments also make it difficult to manage signing credentials, environment configurations, track releases, and to collaborate as a team.
Appflow is the cloud mobile DevOps platform built by Ionic. Using a service like Appflow to build React Native apps not only provides access to powerful computing resources, it can simplify the deployment process by providing a centralized environment for managing and distributing your app to multiple platforms. This can save time and resources, enable collaboration, as well as improve the overall reliability and scalability of an app.
In this workshop, you’ll deploy a React Native application for delivery to Android and iOS test devices using Appflow. You’ll also learn the steps for publishing to Google Play and Apple App Stores. No previous experience with deploying native applications is required, and you’ll come away with a deeper understanding of the mobile deployment process and best practices for how to use a cloud mobile DevOps platform to ship quickly at scale.
Build a chat room with Appwrite and React
JSNation 2022JSNation 2022
41 min
Build a chat room with Appwrite and React
WorkshopFree
Wess Cope
Wess Cope
API's/Backends are difficult and we need websockets. You will be using VS Code as your editor, Parcel.js, Chakra-ui, React, React Icons, and Appwrite. By the end of this workshop, you will have the knowledge to build a real-time app using Appwrite and zero API development. Follow along and you'll have an awesome chat app to show off!
Hard GraphQL Problems at Shopify
GraphQL Galaxy 2021GraphQL Galaxy 2021
164 min
Hard GraphQL Problems at Shopify
WorkshopFree
Rebecca Friedman
Jonathan Baker
Alex Ackerman
Théo Ben Hassen
 Greg MacWilliam
5 authors
At Shopify scale, we solve some pretty hard problems. In this workshop, five different speakers will outline some of the challenges we’ve faced, and how we’ve overcome them.

Table of contents:
1 - The infamous "N+1" problem: Jonathan Baker - Let's talk about what it is, why it is a problem, and how Shopify handles it at scale across several GraphQL APIs.
2 - Contextualizing GraphQL APIs: Alex Ackerman - How and why we decided to use directives. I’ll share what directives are, which directives are available out of the box, and how to create custom directives.
3 - Faster GraphQL queries for mobile clients: Theo Ben Hassen - As your mobile app grows, so will your GraphQL queries. In this talk, I will go over diverse strategies to make your queries faster and more effective.
4 - Building tomorrow’s product today: Greg MacWilliam - How Shopify adopts future features in today’s code.
5 - Managing large APIs effectively: Rebecca Friedman - We have thousands of developers at Shopify. Let’s take a look at how we’re ensuring the quality and consistency of our GraphQL APIs with so many contributors.