Executing a process that transitioned from TypeScript to ES5 and finally to WebPack

Currently, I am attempting to execute the example provided by cycle.js. According to the documentation, it is recommended to use a bundling tool such as browserify or webpack alongside ES6 (also known as ES2015) through a transpiler like Babel or TypeScript.

"We recommend the use of a bundling tool such as browserify or webpack, in combination with ES6 (a.k.a. ES2015) through a transpiler (e.g. Babel or TypeScript)"

To follow these recommendations, I am transpiling from TypeScript to ES5 and then using WebPack from the command line, all in order to eventually call runApp();

In my tsconfig.json file:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5",
    "module": "es6",
    "lib": [
      "es2015",
      "es5",
      "dom"
    ]
  },
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": true
}

Within MyScript.ts:

import { run } from '@cycle/run';
import { makeDOMDriver, div, button } from '@cycle/dom';
function main(sources) {
    var add$ = sources.DOM
        .select('.add')
        .events('click')
        .map(function (ev) { alert('hi'); return 1; });
    var count$ = add$.fold(function (total, change) { return total + change; }, 0);
    return {
        DOM: count$.map(function (count) {
            return div('.counter', [
                'Count: ' + count,
                button('.add', 'Add')
            ]);
        })
    };
}
var drivers = {
    DOM: makeDOMDriver('.app')
};
function runApp() {
    run(main, {
        DOM: makeDOMDriver('#app')
    });
}

Upon transpilation, MyScript.js is generated:

import { run } from '@cycle/run';
import { makeDOMDriver, div, button } from '@cycle/dom';
function main(sources) {
    var add$ = sources.DOM
        .select('.add')
        .events('click')
        .map(function (ev) { alert('hi'); return 1; });
    var count$ = add$.fold(function (total, change) { return total + change; }, 0);
    return {
        DOM: count$.map(function (count) {
            return div('.counter', [
                'Count: ' + count,
                button('.add', 'Add')
            ]);
        })
    };
}
var drivers = {
    DOM: makeDOMDriver('.app')
};
function runApp() {
    run(main, {
        DOM: makeDOMDriver('#app')
    });
}
//# sourceMappingURL=MyScript.js.map

After running

webpack .\MyScript.js MyScriptWebPack.js
,

I have included MyScriptWebPack.js in my project. Despite having no errors, I am unsure how to properly call runApp();

Answer №1

I am unsure of the process to invoke runApp()

Your codebase must include a call to runApp such as:

function runApp() {
    run(main, {
        DOM: makeDOMDriver('#app')
    });
}
runApp(); // Initiate the application

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to directly declare multiple variables within an array in TypeScript?

I am looking to simplify my variable declaration process for an array in my Angular 8 project using TypeScript. Currently, my code looks like this: export class GridComponent { pizza0: Pizza; pizza1: Pizza; pizza2: Pizza; pizza3: Pizza; pizza ...

What is a way to merge all the letters from every console.log result together?

I'm encountering an issue - I've been attempting to retrieve a string that provides a link to the current user's profile picture. However, when I use console.log(), the output appears as follows: Console Output: https://i.sstatic.net/70W6Q ...

Unable to retrieve data from an API using a service in Angular2

[I am attempting to integrate this API file into Angular using a service. Previously, I had success with calling a local JSON file effortlessly, but I am encountering issues with this new one. The second image depicts the table layout I aim to create for t ...

How to retrieve an array stored within a JSON object

I am trying to access a specific array within an object from a JSON file. Here is the snippet of the data I'm dealing with: best-sellers": [ { "title": "Chuteira Nike HyperVenomX Proximo II Society", "price": 499.90, "installmen ...

The lingering output from the problemMatcher in Visual Studio Code persists even after the issue has been resolved

Hello, I have a task set up in npm where I monitor changes in my TypeScript application, compile it, and run tests automatically. My goal is to have Visual Studio Code alert me in the Problems tab whenever a test fails. Although I've successfully ach ...

Convert a Java library to JavaScript using JSweet and integrate it into an Angular project

Just recently, I embarked on my journey to learn TypeScript. To challenge my newfound knowledge, I was tasked with transpiling a Java library using JSweet in order to integrate it into an Angular project. This specific Java library is self-contained, consi ...

Preparing JSON data for use with chart.js leveraging Angular 4 observables

Struggling to make sense of this dilemma, I find myself unable to crack the code. The data retrieved from my API is structured in the following format: "data": [ { "sr_count": 91, "month_name": "October", "month_num": 10, ...

What is the reason behind tsc disregarding the include and exclude options in tsconfig.json?

I am facing an issue with my tsconfig.json file: { "compilerOptions": { "target": "ES6", "lib": [ "DOM", "ES6" ] }, "include": [ "src/server/**/*&q ...

Why is my custom 404 page failing to load after building my Next.js application?

I recently set up a custom 404 page for my Next.js app and wanted to test it locally before deploying to the server. To do this, I used the "serve" package to host the project on my local machine. However, when I tried navigating to a non-existent page, th ...

Parsing error occurred with Bootstrap CSS during Webpack module processing

Dealing with webpack configuration issues Running npm command for build Encountering an error message as below ERROR in ./node_modules/bootstrap/dist/css/bootstrap.min.css 1:0 Module parse failed: Unexpected character '@' (1:0) You may need ...

Can you explain the purpose of the `webpack` function?

I have been using Webpack for quite some time now and I always seem to get tangled up in the configurations. Recently, I attempted to enable intellisense with Webpack in VSCode and discovered that webpack is actually a function. This revelation was exciti ...

angular 2 loading elements synchronously

Within my local or session storage, there exists a JWT token containing the userId information. When a user refreshes the page on a route such as test.com/route2 the app.components.ts initiates an http request to fetch the roles. constructor( p ...

Encountered a snowflake SDK issue which resulted in a TypeError: Unable to access properties of undefined (specifically reading 'set') within OcspResponseCache.set

My current setup includes node version v17.9.0 running on a Linux OS within a Kubernetes environment. I am launching a Node.js application to interact with Snowflake and run queries. The versions of snowflake-promise and snowflake-sdk being used are 2.2.0 ...

Objects That Are Interconnected in Typescript

I have been delving into TS and Angular. I initially attempted to update my parent component array with an EventEmitter call. However, I later realized that this was unnecessary because my parent array is linked to my component variables (or so I believe, ...

Can an object's keys be strongly typed according to array values?

To utilize normalized data effectively, I have created an object with keys that can only be a list of numbers within a specified array. Is there a way to enforce this restriction in typing so that if I attempt to access the object using a non-array key, an ...

Building a personalized Angular component to encapsulate an input field for use in reactive forms

I'm struggling to create a personalized component that includes an input form control. I'm unsure how to properly link the formControl directive and formControlName to the input element within my code. Here is what I have so far: <div class=" ...

Angular 13 ng-bootstrap date field sortable table

I need help sorting an Observable Array with Date datatype using the Sort() method in Angular 13. You can find an example at: https://stackblitz.com/edit/ngbootstrap-table-sorting-aabk9h?file=app%2Ftable-sortable.ts Here is my table-sortable.html: <ng ...

Guide on deploying a web application using Socket.io and SvelteKit on Vercel

Currently, I'm developing a multiplayer .io-style game that utilizes both Socket.io and SvelteKit. While testing the project on a local development server, everything runs smoothly. However, upon deploying to Vercel, an error message stating Failed to ...

Ensure that the user-entered text input is validated within a table using Angular 5

HTML file <mat-table #table [dataSource]="CMDataSource"> <ng-container matColumnDef="mQues"> <mat-header-cell *matHeaderCellDef> Ticket Volume </mat-header-cell> <mat-cel ...

'map' is not defined in the current Typescript scope

As a newcomer to AngularJS, I am encountering an error when attempting to send a post request to my localhost server. The error message states [ts] cannot find name 'map' and cannot find name 'subscribe'. Any assistance in understanding ...