question: using subscribers on vanilla javascript
See original GitHub issueIssue type:
[X] question [ ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[X] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[ ] latest
[ ] @next
[X] 0.2.6
(or put your version here)
I’m trying to configure subscribers using Javascript, but the beforeInsert method on my Subscriber class never get called… Maybe I’m missing some step or configuration?
Doc: https://github.com/typeorm/typeorm/blob/master/docs/connection-options.md
My code looks like this:
class Subscriber {
beforeInsert (event) {
console.log('fooo', event)
}
}
module.exports = {
name: 'default',
type: 'postgres',
host: process.env.DB_HOST,
port: process.env.DB_PORT,
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
entities: schemas.map(schema => new EntitySchema(schema)),
synchronize: false,
logging: true,
subscribers: [ Subscriber ],
extra: { max: 1 },
migrations: [path.join(__dirname, '../../migrations/*.js')],
cli: { migrationsDir: path.join(__dirname, '../../migrations/*.js') },
logger: new QueryLogger()
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
JavaScript Design Patterns Part 2: The Publisher/Subscriber ...
The Publisher/Subscriber pattern, or “PubSub” for short, is a pattern that allows us to create modules that can communicate with each other ...
Read more >Use Observables with Vanilla JavaScript | Ahmed Tarek
This Subscription object should expose an unsubscribe function. unsubscribe should be called by the observer whenever he wants to stop listening ...
Read more >Observer Pattern with Vanilla JS - Under The Hood Learning
The Observer is a behavioral design pattern that lets you define a subscription mechanism to notify multiple objects about any events that happen...
Read more >What are your vanilla JavaScript knowledge standards that ...
I take issue with some of these questions insofar as "vanilla JS" is pure JS and not necessarily DOM API (I define vanilla...
Read more >How to create an ApolloClient subscription in vanilla js
... in the ApolloClient 'link' meant it was setup only for http, I can confirm that the code above works just fine with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Has anyone advanced this? This is a bit old but running into this issued right now for listeners and subscribers in javascript.
For those who still have some trouble to use Subscribers in vanilla, here is my solution:
I’ve created an utility function to apply decorators into classes:
And then use the decorators:
The DecorateClass function will only work on Classes, to decorate a method the implementation must be different…