Skip to content

Commit 5b7129a

Browse files
committed
Fix UX Turbo usage without Streams
1 parent 536e836 commit 5b7129a

File tree

6 files changed

+161
-3
lines changed

6 files changed

+161
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["@babel/env"],
3+
"plugins": ["@babel/plugin-proposal-class-properties"]
4+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"use strict";
2+
3+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4+
5+
Object.defineProperty(exports, "__esModule", {
6+
value: true
7+
});
8+
exports["default"] = void 0;
9+
10+
var _stimulus = require("stimulus");
11+
12+
var Turbo = _interopRequireWildcard(require("@hotwired/turbo"));
13+
14+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
15+
16+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17+
18+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19+
20+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
21+
22+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
23+
24+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
25+
26+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
27+
28+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
29+
30+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
31+
32+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
33+
34+
// Expose Turbo to the rest of the app to allow for dynamic Turbo calls
35+
window.Turbo = Turbo;
36+
/**
37+
* Empty Stimulus controller only used for Symfony Flex wiring.
38+
*
39+
* @author Titouan Galopin <galopintitouan@gmail.com>
40+
*/
41+
42+
var _default = /*#__PURE__*/function (_Controller) {
43+
_inherits(_default, _Controller);
44+
45+
var _super = _createSuper(_default);
46+
47+
function _default() {
48+
_classCallCheck(this, _default);
49+
50+
return _super.apply(this, arguments);
51+
}
52+
53+
return _default;
54+
}(_stimulus.Controller);
55+
56+
exports["default"] = _default;

src/Turbo/Resources/assets/package.json

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,39 @@
44
"license": "MIT",
55
"private": true,
66
"version": "0.1.0",
7+
"symfony": {
8+
"controllers": {
9+
"turbo-core": {
10+
"main": "dist/turbo_controller.js",
11+
"webpackMode": "eager",
12+
"fetch": "eager",
13+
"enabled": true
14+
}
15+
}
16+
},
717
"scripts": {
8-
"build": "echo skip",
9-
"test": "echo skip",
10-
"lint": "echo skip"
18+
"build": "babel src -d dist",
19+
"test": "babel src -d dist && jest",
20+
"lint": "eslint src test"
1121
},
1222
"dependencies": {
1323
"@hotwired/turbo": "^7.0.0-beta.4"
24+
},
25+
"peerDependencies": {
26+
"stimulus": "^2.0.0"
27+
},
28+
"devDependencies": {
29+
"@babel/cli": "^7.12.1",
30+
"@babel/core": "^7.12.3",
31+
"@babel/plugin-proposal-class-properties": "^7.12.1",
32+
"@babel/preset-env": "^7.12.7",
33+
"@symfony/stimulus-testing": "^1.1.0",
34+
"stimulus": "^2.0.0"
35+
},
36+
"jest": {
37+
"testRegex": "test/.*\\.test.js",
38+
"setupFilesAfterEnv": [
39+
"./test/setup.js"
40+
]
1441
}
1542
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* This file is part of the Symfony package.
3+
*
4+
* (c) Fabien Potencier <fabien@symfony.com>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
import { Controller } from 'stimulus';
11+
import * as Turbo from '@hotwired/turbo';
12+
13+
// Expose Turbo to the rest of the app to allow for dynamic Turbo calls
14+
window.Turbo = Turbo;
15+
16+
/**
17+
* Empty Stimulus controller only used for Symfony Flex wiring.
18+
*
19+
* @author Titouan Galopin <galopintitouan@gmail.com>
20+
*/
21+
export default class extends Controller {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* This file is part of the Symfony package.
3+
*
4+
* (c) Fabien Potencier <fabien@symfony.com>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
import '@symfony/stimulus-testing/setup';
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* This file is part of the Symfony package.
3+
*
4+
* (c) Fabien Potencier <fabien@symfony.com>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
'use strict';
11+
12+
import { Application } from 'stimulus';
13+
import { getByTestId } from '@testing-library/dom';
14+
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
15+
import TurboController from '../src/turbo_controller';
16+
17+
const startStimulus = () => {
18+
const application = Application.start();
19+
application.register('symfony--ux-turbo--turbo', TurboController);
20+
};
21+
22+
/* eslint-disable no-undef */
23+
describe('TurboStreamController', () => {
24+
let container;
25+
26+
beforeEach(() => {
27+
container = mountDOM('<div data-testid="turbo-core" data-controller="symfony--ux-turbo--turbo"></div>');
28+
});
29+
30+
afterEach(() => {
31+
clearDOM();
32+
});
33+
34+
it('connects', async () => {
35+
startStimulus();
36+
37+
// smoke test
38+
expect(getByTestId(container, 'turbo-core')).toHaveAttribute('data-controller', 'symfony--ux-turbo--turbo');
39+
});
40+
});

0 commit comments

Comments
 (0)