obseriot

WebJar for obseriot

Лицензия

Лицензия

MIT
Группа

Группа

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

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

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

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

0.3.9
Дата

Дата

Тип

Тип

jar
Описание

Описание

obseriot
WebJar for obseriot
Ссылка на сайт

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

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

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

https://github.com/obseriot/obseriot

Скачать obseriot

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

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

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.webjars.npm : riot-observable jar [3.0.0]

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

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

Simple observer pattern

Install

npm install obseriot

Usage

Define event

Object with a handler.name and handler.action .

  • handler.name => Event name
  • handler.action => Return the parameters to be provided to the listener
    • Array is provided as a variadic argument
    • Can be provide a variety of types. String, Object, Function, whatever
const urlChange = {
    handler: {
        name: 'url_change',
        action ( collection, id, action ) {
            // Some processing and formatting
            return [ collection, id, action ]
        }
    }
}

Listen and Notify

// obseriot.listen( event object , callback function )
obseriot.listen( urlChange, ( ...arg ) => {
    console.log( arg ) // => 'shop', 1, 'detail'
} )

// obseriot.notify( event object , parameters )
obseriot.notify( urlChange, 'shop', 1, 'detail' )

One time listener

// obseriot.once( event object , callback function )
obseriot.once( urlChange, ( ...arg ) => {
    console.log( arg )
} )

Remove listeners

Remove all registered listeners.

// obseriot.remove( event object )
obseriot.remove( urlChange )

Remove one registered listener.

// obseriot.remove( event object, callback function )
const callback = ( ...arg ) => {
    console.log( arg )
}
obseriot.listen( urlChange, callback ) // Listen to the named function.
obseriot.remove( urlChange, callback ) // Remove!

How to use like Flux

Define Action

export const increment = {
    handler: {
        name: 'action_increment',
        action ( num = 1 ) {
            return [ num ]
        }
    }
}

Define Store

import {increment} from './action/increment'
import obseriot from 'obseriot'

export const count = {
    state: 0,
    handler: {
        name: 'store_count',
        action () {
            return [ count.state ]
        }
    }
}

obseriot.listen( increment, num => {
    count.state = count.state + num
    obseriot.notify( count )
} )

Your Component

import {increment} from './action/increment'
import {count} from './store/count'
import obseriot from 'obseriot'

// Action in somewhere components
obseriot.notify( increment, 1 )

// Listen to Store update
obseriot.listen( count, newCount => {
    console.log( newCount ) // => 1
} )

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

Версия
0.3.9