Comments (7)
I think you can just add in the copyright to the json document in a "get" listener. I'll look into adding another listener for right before sending, but I don't think that's necessary for this.
I'm not sure exactly how you're going to add the copyright. Are you tg
from expressa.
Sorry I posted too soon by accident. Are you going to add a field to the output or are you going to add a header. Otherwise, just adding text before or after would break Jon parsing.
from expressa.
Cool, thanks.
Let's say I have several docs. Right now, they come in as an array. I'd like to be able to add everything to a root item like 'data'.
Then, at the end, I'd like to add a copyright statement off the root. Something like 'copyright' :'message'.
Having this global feature would let me manipulate the final json before its sent out, not just the document inside the array.
Make sense?
from expressa.
Yep, that makes perfect sense. Thanks for the detailed explanation! I've just committed a "getpresend" listener that does what you're looking for, but I haven't pushed out a new npm version because I'm not sure about the name yet.
from expressa.
Nice! Let me take a look at it and I'll come back to you.
What's in a name, right? :)
from expressa.
Hey again.
I can see the event firing correctly, but it doesn't seem as though I can manipulate the doc and pass it back to the response. Here's my bit of code:
expressa.addListener('getpresend',1, function(req, collection, doc) {
return new Promise(function(resolve, reject) {
doc = JSON.parse(JSON.stringify(doc).split('"Title":').join('"new_title":'));
console.log(doc) // **<-- this works and prints out the expected result to the console**
resolve() // **<-- I'd expect this to return the modified doc, but instead, it returns the original.**
})
})
I can't seem to manipulate and return the doc as I would expect to. Any suggestions on what I'm doing wrong?
from expressa.
I think the problem here is that you're replacing the "doc" variable. Since JavaScript passes by value, the caller of your listener function doesn't see the change. There's two potential solutions.
- Use Object.assign
expressa.addListener('getpresend',1, function(req, collection, doc) {
modified = JSON.parse(JSON.stringify(doc).split('"status":').join('"status222":'));
Object.assign(doc, modified)
})
- Use something like this function instead of doing string replacement.
Also, note that since you're not doing any async operations (e.g. file IO, network requests, database lookups) the promise is unnecessary.
from expressa.
Related Issues (20)
- update with query HOT 1
- Property Type Any HOT 3
- Admin Panel - Media Problems
- Admin Panel - Display Error Message HOT 1
- Admin Panel - File Loading HOT 2
- Stale Router Settings HOT 8
- Admin - Use Fields for Collection List HOT 3
- 1.0.1 Error on Startup HOT 5
- Admin - Cant Update User HOT 2
- Fields with GET Bug HOT 6
- Allow Admin role Changes to be kept HOT 1
- Pagination Optimize HOT 2
- Mongo Projection HOT 4
- cacheInMemory with Redis HOT 3
- updateWithQuery error HOT 2
- register and login listeners HOT 3
- Include old doc as parameter for listeners HOT 1
- Session Expire on Password Change
- Auto Lowercase Email HOT 1
- updating _id doesnt update id column HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expressa.