window-or-global

WebJar for window-or-global

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

window-or-global
Последняя версия

Последняя версия

1.0.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

window-or-global
WebJar for window-or-global
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/purposeindustries/window-or-global

Скачать window-or-global

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/window-or-global/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>window-or-global</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/window-or-global/
implementation 'org.webjars.npm:window-or-global:1.0.1'
// https://jarcasting.com/artifacts/org.webjars.npm/window-or-global/
implementation ("org.webjars.npm:window-or-global:1.0.1")
'org.webjars.npm:window-or-global:jar:1.0.1'
<dependency org="org.webjars.npm" name="window-or-global" rev="1.0.1">
  <artifact name="window-or-global" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='window-or-global', version='1.0.1')
)
libraryDependencies += "org.webjars.npm" % "window-or-global" % "1.0.1"
[org.webjars.npm/window-or-global "1.0.1"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

window-or-global

Use this module to get the global object both on server and client side. No more window is not defined errors just peace and flowers.

The code is borrowed from megawac/underscore@365311c.

Advantages:

  • You can easily mock it by mockery or proxyquire in your tests
  • It's really useful in case of universal (or isomorphic) code, for example, when you'd like to render a React component both on client and server side

Install

$ npm i window-or-global

Usage

import root from 'window-or-global'

React example

components/my-component.jsx:

import React, { Component } from 'react'
// in node, you'll get the global object instead of crashing by an error
import root from 'window-or-global'

class MyComponent extends Component {

  // this method is only invoked in the browser environment
  componentDidMount() {
    root.addEventListener(/*...*/)
  }

  componentWillUnmount() {
    root.removeEventListener(/*...*/)
  }

  render() {}

}

// Voilà. Enjoy your universal react component! ;)
// No more 'window is not defined' errors when you render your component
// on server side.

Unit-testing example

You can find a complete test example here. The test passes of course, just type

$ npm test

in your terminal.

License

MIT © Purpose Industries

org.webjars.npm

Purpose Industries

Версии библиотеки

Версия
1.0.1