Coder Social home page Coder Social logo

ember-network's Introduction

ember-network

๐Ÿ”ฅ Deprecation Notice ๐Ÿ”ฅ

ember-network is deprecated in favor of ember-fetch.

Originally, ember-network was created to contain implementations of multiple networking primitives that worked in both the browser and Node.js. However, given the rapid adoption of the WHATWG Fetch and FastBoot's built-in support for the jQuery AJAX-like najax, there is little reason for ember-network to continue to exist.

You should be able to seamlessly switch to ember-fetch, which uses the same underlying fetch polyfills.

Ember Network provides low-level networking primitives that work both in the browser and in Node.js via FastBoot.

Usage

Currently, Ember Network implements the WHATWG Fetch standard. Other standards may be implemented in the future.

Fetch

import Route from "ember-route";
import fetch from "ember-network/fetch";

export default Route.extend({
  model() {
    return fetch('https://api.github.com/users/tomdale/events')
      .then(function(response) {
        return response.json();
      });
  }
});

For more information on using fetch(), see:

To see a very simple example app using FastBoot and Ember Network, see:

Testing

Testing requires a new approach because existing tools like Pretender and Mirage rely on ajax and XMLHttpRequest. Newer browsers have the fetch command built in, therefore mocking it is a bit different.

Firstly remove local reference from your fetch import statement:

import 'ember-network/fetch';

Because we will be mocking the global fetch, having a local reference will miss out on the mocked version. Now we are ready for mocking:

npm install fetch-mock
ember install ember-browserify

Now, inside of any acceptance tests, you can mock any network traffic with ease:

// ...
import fetchMock from 'npm:fetch-mock';

// ...

test('visiting /', function(assert) {
  fetchMock.get('/users/1', {
    'data': {
      'type': 'user',
      'id': '1',
      'attributes': {
        // ...
      }
    }
  });

  visit('/');
  
  // ...
});

How It Works

At build time, Ember Network detects if the build target is FastBoot or the browser. For FastBoot, it swaps in the node-fetch library. For the browser, it swaps in GitHub's fetch polyfill. (The browser polyfill will use the native window.fetch() if available.) The appropriate version will appear in your vendor.js file.

If you'd like to write an Ember addon that does something similar, please see the annotated index.js file.

ember-network's People

Contributors

alicelupsan avatar alinilea avatar ember-tomster avatar locks avatar olleolleolle avatar stefanpenner avatar tomdale avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ember-network's Issues

Testing when used inside component

Is this compatible with the wait test helper?

I'm using fetch inside a component and I need to write an integration test for my component. I can't escape the error Assertion after the final assert.async was resolved though. I've tried several techniques to no avail.

Error: ENOENT: no such file or directory : module-template.js.t

Hi,

I have this problem on private project build.

I remember another problem like this when to solve I moved a file during build, but I don't remember exactly the path of file.

Any idea abou this problem?
Thanks!

โžœ  my_project git:(my_branch) โœ— ember s
DEPRECATION: ember-cli-test-loader should now be included as an NPM module with version 1.1.0 or greater.
Livereload server on http://localhost:49153
Serving on http://localhost:4200/
The Broccoli Plugin: [object Object] failed with:
Error: ENOENT: no such file or directory, stat '/home/wellington/my_project/node_modules/ember-network/assets/module-template.js.t'
  at Error (native)
  at Object.fs.statSync (fs.js:844:18)
  at Filter.Template.currentTemplateFile (/home/wellington/my_project/node_modules/broccoli-templater/index.js:22:18)
  at Filter.Template.processAndCacheFile (/home/wellington/my_project/node_modules/broccoli-templater/index.js:45:27)
  at /home/wellington/my_project/node_modules/broccoli-templater/node_modules/broccoli-filter/index.js:43:23
  at /home/wellington/my_project/node_modules/promise-map-series/index.js:11:14
  at tryCatch (/home/wellington/my_project/node_modules/rsvp/dist/rsvp.js:539:12)
  at invokeCallback (/home/wellington/my_project/node_modules/rsvp/dist/rsvp.js:554:13)
  at /home/wellington/my_project/node_modules/rsvp/dist/rsvp.js:629:16
  at flush (/home/wellington/my_project/node_modules/rsvp/dist/rsvp.js:2414:5)
  at nextTickCallbackWith0Args (node.js:436:9)
  at process._tickCallback (node.js:365:13)


The broccoli plugin was instantiated at: 
undefined


cleaning up...

App build broken

Build failed.
The Broccoli Plugin: [object Object] failed with:
undefined

The broccoli plugin was instantiated at:
undefined

Similar to ember-cli/ember-cli#5571
Win10, cli 2.4.2, node 5.7.0, npm 5.6.0

Error: Cannot find module 'node-fetch'

There was an error running your app in fastboot. More info about the error: 
 Error: Cannot find module 'node-fetch'

I'm not convinced this is a bug in this repo. I'm using ember-cli-moment-shim successfully in fastboot and the moment require is working. I don't know what's different about this addon that the node-fetch won't resolve. I've read through all the code here and couldn't find the issue. Do you have any pointers for me? I've tried npm i node-fetch to flatten the module, but that didn't help.

npm ls node-fetch
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ””โ”€โ”ฌ [email protected]
โ”‚     โ””โ”€โ”€ [email protected] 
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ””โ”€โ”€ [email protected] 
โ””โ”€โ”€ [email protected]  extraneous

Broken when used form an addon

โ ‹ Buildingapp.import is not a function
TypeError: app.import is not a function
    at Class.module.exports.included (/Users/tchak/git/github/ember-cli/ember-ajax/node_modules/ember-network/index.js:17:15)
    at /Users/tchak/git/github/ember-cli/ember-ajax/node_modules/ember-cli/lib/models/addon.js:244:32

Steps to reproduce:

  • create a new addon
  • ember install ember-network
  • ember test
  • ๐Ÿ’ฃ

Test set up install error

I'm trying to follow the set up in the Testing section of the README. When I ran ember install fetch-mock ember-browserify I get this error: Install failed. Could not find addon with name: fetch-mock

I think this should be:

npm install fetch-mock
ember install ember-browserify

Right?

deprecate in-favour of ember-fetch

  • its actively maintained
  • its the original (not sure why the work here wasn't a contribution to ember-fetch)

I suspect ember-network aim(s|ed) to be more lofty, supporting other protocols. Maybe we should resurrect when it does support more, or is that inbound?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.