Giter VIP home page Giter VIP logo

history's Introduction

Cycle.js

logo
A functional and reactive JavaScript framework for predictable code

Welcome

Question Answer
"I want to learn Cycle.js" Read the official documentation
"I have a question" Create a StackOverflow question
Or
Join the chat
Or
Open an issue
Please note all discussion-like issues are labeled discussion and immediately closed. This doesn't mean we unconsidered your discussion. We only leave actual issues open.
"I found a bug" Open an issue
"I want to help build Cycle.js" Read the Contributing guides
Then
Choose an issue marked "help wanted"

Packages

Cycle.js is comprised of many specialized packages. This repository contains all these packages, e.g., the npm package @cycle/run lives in the directory run. Below you will find a summary of each package.

Package Version Dependencies DevDependencies
@cycle/dom npm (scoped) Dependency Status devDependency Status
@cycle/history npm (scoped) Dependency Status devDependency Status
@cycle/html npm (scoped) Dependency Status devDependency Status
@cycle/http npm (scoped) Dependency Status devDependency Status
@cycle/isolate npm (scoped) Dependency Status devDependency Status
@cycle/most-run npm (scoped) Dependency Status devDependency Status
@cycle/run npm (scoped) Dependency Status devDependency Status
@cycle/rxjs-run npm (scoped) Dependency Status devDependency Status

Globally: Build Status devDependency Status

Stream libraries

The following packages are not under Cycle.js, but are important dependencies, so we display their latest versions for convenience.

Package Version
most npm version
rxjs npm version
xstream npm version

Support OpenCollective OpenCollective

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Thanks

Browserstack

Browserstack for providing access to their great cross-browser testing tools.

LICENSE

The MIT License


JS.ORG ComVer

history's People

Contributors

michalvankodev avatar staltz avatar tylors avatar vinnl avatar wclr 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

history's Issues

Routing does not switch away from a constantly updating page

I have routes defined like the following. The foo page updates every second.

const routes = {
  '/': h('h1', {}, 'Home'),
  '/test': h('h1', {}, 'test'),
  '/foo': function() {
    return {
      DOM: Rx.Observable.interval(1000).map(i=>h('div', i+''))
    }
  }
};

I use cycle-starter's code to handle the view switch:

function createRouteValue(sources) {
  return function getRouteValue(location) {
    const {value} = switchPath(location.pathname, routes);
    console.log(location.pathname);
    if (typeof value === `function`) {
      const dialogue = value(sources);
      return dialogue;
    }
    return value;
  };
}

function main(sources) {
  const contentView$ = sources.History.map(createRouteValue(sources))
    .flatMap(value => {
      if (value.DOM) {
        return value.DOM;
      }
      return Rx.Observable.just(value);
    });

  const navButtons = NavButtons(sources);

  const view$ = Rx.Observable.just(h('div', [contentView$, navButtons.DOM]));

  return {
    DOM: view$,
    History: navButtons.url$
  };
}

The problem is that once I switch into the foo page, I can't navigate away. I can temporarily navigate to another page, and the location bar updates too, but the foo page always comes back.

makeHistoryDriver throws error for a proper history object

This is the test code:

import Cycle from '@cycle/core';
import {div, makeDOMDriver} from '@cycle/dom'
import {makeHistoryDriver} from '@cycle/history' // version 2.0.1
import {makeRouterDriver} from 'cyclic-router'
import {createHistory} from 'history' // version 2.0.1
import Rx from 'rx'

function main(sources) {
    const view$ = Rx.Observable.just("Hello World")
    return {
        DOM: view$
    }
}

const history = createHistory()

console.log("typeof history: " + typeof history)
console.log("typeof history.createLocation: " + typeof history.createLocation)
console.log("typeof history.createHref: " + typeof history.createHref)
console.log("typeof history.push: " + typeof history.push)
console.log("typeof history.listen: " + typeof history.listen)

// Below is the copied from makeHistoryDriver code, just to make sure...
  if (!history || typeof history !== `object` ||
    typeof history.createLocation !== `function` ||
    typeof history.createHref !== `function` ||
    typeof history.listen !== `function` ||
    typeof history.push !== `function`)
  {
    console.log("Test failed")  // <- is not triggered so test is OK
  }

const drivers = {
    DOM: makeDOMDriver("#app"),
    router: makeRouterDriver(makeHistoryDriver(history))
}

Cycle.run(main, drivers)

I use browserify (version 13.0.0). The console output in Chrome is:

typeof history: object
typeof history.createLocation: function
typeof history.createHref: function
typeof history.push: function
typeof history.listen: function
Uncaught TypeError: makeHistoryDriver requires an valid history object containing createLocation(), createHref(), push(), and listen() methods

How come this error is triggered even though history seems to be a valid history object?

`makeHistoryDriver` should output the initial location.

From my understanding, from Cycle.js's viewpoint, imperative APIs such as history.replace should be run through drivers.
I think that's why the location object accessible from source observable has some additional functions, like location.replace or location.goBack.
However, I found the initial location is not emitted for 1.1.0, which means I should access the history object myself outside of drivers to use such functions on the initial page.
I tried working around like this,

function makeStartedHistoryDriver() {
  return url$ => {
    let driver = makeHistoryDriver();
    return driver(
      url$.startWith(window.location.pathname)
    );
  };
}

but this duplicates the initial location in history list. (window.location.pathname pushed unnecessarily)
Am I properly understanding the framework?

Update to history 3.0.0

History 3.0.0 has some breaking changes, need to more closely investigate what they are and how they affect things.

With v3.0.0 it now also provided a dist/ build via npmcdn, we should also now create dist/ build of @cycle/history.

In Universal example issue with ongoingContext$ in app.js file...

so after using the Universal / Isomorphic example from link here and adding cycle-history I get an issue in app.js on this line

let routeFromClick$ = ext.DOM.select('.link').events('click')
    .doOnNext(ev => ev.preventDefault())
    .map(ev => ev.currentTarget.attributes.href.value);

let ongoingContext$ = ext.context
// this line bellow is throwing the error
    .merge(routeFromClick$).scan((acc, x) => {
      acc.route = x;
      return acc;
    });
TypeError: Cannot read property 'merge' of undefined

Not entirely sure if the app.js function needs to also change?

Same history instance for HistoryDriver and ReactRouter

Hi,
great work. I use Cycle as a replacement to Flux in my React App which uses ReactRouter. I would like to use HistoryDriver so that I can change history state or react to history changes in my services (models) (independent from React).

I assume that I need the same history instance for both and there is no way how to get or set history instance in HistoryDriver.

It would help if I could provide history instance when creating HistoryDriver. Probably by changing to function makeHistoryDriver(config, history) { ... }?

Navigating to a url, then hitting browser back, followed by attempting to navigate to the same page again dosen't work.

This issue is caused by .distinctUntilChanged() used within the historyDriver function.

Navigating to a new route, followed by hitting the back button and attempting to navigate to the same route fails because distinctUntilChanged is used. When it comes to browser history i'm not entirely certain distinctUntilChanged is required. Has it been put in there for any other particular reason?

captureClicks captures anchor link clicks

<a href='#myAnchor'>...</a>

Expected behaviour: page jumps to anchor element
Actual behaviour: router re-runs current component/app

I can submit a PR if wanted. I think it's just a matter of changing

captureClicks.js:42

if (link && link.indexOf('mailto:') > -1 || link === '#') {
    return;
}

to

if (link && link.indexOf('mailto:') > -1 || link.charAt(0) === '#') {
    return;
}

Something extra may be needed though to scroll down to the appropriate element after render if a hash link is visited directly/typed into address bar (i.e. http://localhost:3000/#myAnchor).

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.