Comments (9)
Use the Bliss $.type()
function. Your check would fail if the object comes from another window/frame.
from bliss.
Is the fetch
function still needed? Is it stated somewhere what range of browser versions this is now intended for?
from bliss.
I'm already wrapping Bliss.fetch
, so I'm not in a hurry to get this added. I mainly wanted to share my discoveries (I tried to solve this using query strings at first).
Converting ex: {foo: {bar: 1, x: {y: 'z'}}
to foo[bar=1]&foo[x][y]=z
requires recursion. In the simplest form, something like this:
// Note: This is simplified/dumb version of https://github.com/friday/query-string-encode
function queryStringEncode(input) {
// Array of path/value tuples
var flattened = [];
(function flatten(input, path) {
// Add path and value to flat array
if ([Boolean, Number, String].indexOf(input.constructor) !== -1) {
var serializedPath = path.map(function (key, index) {
return index ? "[" + key + "]" : key;
}).join("");
flattened.push([serializedPath, input]);
}
// Iterate over next level of array/object
else if ([Array, Object].indexOf(input.constructor) !== -1) {
for (var key in input) {
flatten(input[key], path.concat([key]));
}
}
})(input, []);
// Convert array to query string
return flattened.map(function (pair) {
return pair.map(encodeURIComponent).join("=");
}).join("&");
}
from bliss.
The thing is, sometimes we want to send the actual object, e.g. uploading File objects.
So we need to be careful where we apply this stringification.
from bliss.
Yes. Only object literals or objects created with new Object()
should be supported imo. This can be checked using the constructor (and probably many other ways)
({}).constructor === Object // true
new Blob().constructor === Object // false
new FormData.constructor === Object // false
from bliss.
Oh yeah, I recall something about this. Seems this applies to my suggestion as well :(
from bliss.
Seems this applies to my suggestion as well :(
What do you mean?
from bliss.
Oh, I read that too quickly. Nevermind the "as well" part of the comment.
from bliss.
Perhaps not @joyously. However Bliss's Fetch implementation is not a polyfill. It's different from the Fetch standard in small ways that means people who use it can't just drop-in replace the native browser Fetch or a polyfill.
The browser support for Fetch is very good today. When the Fetch API standard was released and got initial browser support you couldn't get any upload/download progress or abort the request. AbortController and ReadableStream were added later to solve that. They're also well supported today, but this adds to more differences in the Fetch API implementation and Bliss's Fetch.
However you're probably right that this issue may not be important today anymore. I'll leave that decision to Lea.
from bliss.
Related Issues (20)
- Handling upload events in $.fetch() via options HOT 3
- Revise default content-type in $.fetch() HOT 3
- NPM package missing minified versions HOT 3
- Files for CDN hosting (cdnjs) HOT 6
- Comment: moving to 'modern' libraries and using the same '_' name HOT 2
- Displaying the implementation in the doc is broken for anything using overload HOT 1
- Non-shy bliss fails in electron
- Memory leak bug in unbind method HOT 1
- Npm package doesn't work, bad code HOT 7
- Rewrite to ESM HOT 1
- TypeError: Cannot read property 'handleEvent' of null HOT 3
- TypeError: evt.target.closest is not a function HOT 1
- Error when a class defined via $.Class() extends an ES6 class HOT 2
- Suggested API for Bliss 2.0 - attributes and class
- Suggested API for Bliss Shy 2.0 - $._ and $$._ HOT 1
- Event Hijack is against "Heavenly JavaScript!" - Bliss Full vs Bliss Shy HOT 1
- [Docs] Table of contents not showing HOT 2
- dataset handling HOT 1
- v2 non-esm version HOT 1
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 bliss.