Giter Club home page Giter Club logo

elmaz's People

Contributors

tunnckocore avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

elmaz's Issues

Weekly Digest (5 May, 2019 - 12 May, 2019)

Here's the Weekly Digest for tunnckoCoreLabs/elmaz:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please ๐Ÿ‘€ Watch and โญ Star the repository tunnckoCoreLabs/elmaz to receive next weekly updates. ๐Ÿ˜ƒ

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. ๐Ÿ“†

Weekly Digest (28 April, 2019 - 5 May, 2019)

Here's the Weekly Digest for tunnckoCoreLabs/elmaz:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please ๐Ÿ‘€ Watch and โญ Star the repository tunnckoCoreLabs/elmaz to receive next weekly updates. ๐Ÿ˜ƒ

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. ๐Ÿ“†

Weekly Digest (24 February, 2019 - 3 March, 2019)

Here's the Weekly Digest for tunnckoCoreLabs/elmaz:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please ๐Ÿ‘€ Watch and โญ Star the repository tunnckoCoreLabs/elmaz to receive next weekly updates. ๐Ÿ˜ƒ

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. ๐Ÿ“†

Weekly Digest (3 March, 2019 - 10 March, 2019)

Here's the Weekly Digest for tunnckoCoreLabs/elmaz:

ISSUES

This week, no issues have been created or closed.

PULL REQUESTS

This week, no pull requests has been proposed by the users.

CONTRIBUTORS

This week, no user has contributed to this repository.

STARGAZERS

This week, no user has starred this repository.

COMMITS

This week, there have been no commits.

RELEASES

This week, no releases were published.

That's all for this week, please watch ๐Ÿ‘€ and star โญ tunnckoCoreLabs/elmaz to receive next weekly updates. ๐Ÿ˜ƒ

Weekly Digest (10 February, 2019 - 17 February, 2019)

Here's the Weekly Digest for tunnckoCoreLabs/elmaz:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please ๐Ÿ‘€ Watch and โญ Star the repository tunnckoCoreLabs/elmaz to receive next weekly updates. ๐Ÿ˜ƒ

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. ๐Ÿ“†

Weekly Digest (12 May, 2019 - 19 May, 2019)

Here's the Weekly Digest for tunnckoCoreLabs/elmaz:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please ๐Ÿ‘€ Watch and โญ Star the repository tunnckoCoreLabs/elmaz to receive next weekly updates. ๐Ÿ˜ƒ

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. ๐Ÿ“†

another

backup

index.js

/**
 * @copyright 2017-present, Charlike Mike Reagent <[email protected]>
 * @license Apache-2.0
 */
import createElement from 'minscript'
import morph from 'minmorph'

const h = createElement
// state management
import createView from './view.js'
import createStore from './store.js'
import createEffects from './effects.js'
import createReducers from './reducers.js'

export { h, createElement, morph, createView, createStore, createEffects, createReducers }

view.js

/**
 * @copyright 2017-present, Charlike Mike Reagent <[email protected]>
 * @license Apache-2.0
 */
import assert from 'assert'
import { isObject } from './utils.js'

export default function createView (store, actions, viewFn) {
  assert(isObject(store), 'expect `store` to be an object')
  assert(isObject(actions), 'expect `actions` to be an object')
  assert(typeof viewFn === 'function', 'expect `viewFn` to be a function')

  let el = null
  let context = {
    state: store.getState(),
    actions,
    done: (er) => {
      store.emit('error', er)
    },
  }

  let view = (...args) => {
    try {
      return viewFn(...args)
    } catch (er) {
      context.done(er)
    }
  }

  store.off('stateChange')
  store.on('stateChange', (ctx) => {
    console.log(ctx.state)
    context = Object.assign({}, context, ctx)
    console.log(context.state)
    store.emit('render', view, context, (fn) => (el = fn(el)))
  })

  store.emit('render', view, context, (fn) => (el = fn(el)))

  return el
}

utils.js

const isObject = (val) => val && typeof val === 'object' && !Array.isArray(val)

export { isObject }

store.js

/**
 * @copyright 2017-present, Charlike Mike Reagent <[email protected]>
 * @license Apache-2.0
 */
import createEmitter from './emitter.js'

export default function createStore (state) {
  const store = createEmitter()

  store._state = state

  // always freezed state object
  store.getState = () => Object.freeze(Object.assign({}, store._state))

  // 1. if `next` function, pass freezed state to it,
  //    and "hard update" the whole state from the return
  // 2. if `next` not function, "soft update" the whole state
  // 3. if `next` nothing, return freezed old state
  store.setState = (nextState, hardUpdate) => {
    if (!nextState) {
      return null
    }

    if (typeof nextState === 'function') {
      return store.setState(nextState({ state: store.getState() }), true)
    }

    const prevState = store.getState()
    const state = hardUpdate
      ? Object.assign({}, nextState)
      : Object.assign({}, prevState, nextState)

    store.emit('stateChange', { prevState, state, nextState })

    // !! Intentionally after the emitting !!
    // User should not expect `store.getState()` from the listener to work.
    // You get any kind of state in that listener's arguments, so - don't!
    store._state = state

    return store._state
  }

  return store
}

emitter.js

/**
 * @copyright 2017-present, Charlike Mike Reagent <[email protected]>
 * @license Apache-2.0
 */
export default function createEmitter (events) {
  events = Object.assign({}, events)

  const app = {
    events,
    on (name, listener) {
      ;(events[name] || (events[name] = [])).push(listener)
    },

    off (name, listener) {
      if (events[name] && listener) {
        events[name].splice(events[name].indexOf(listener) >>> 0, 1)
      } else if (name && !listener) {
        app.events[name] = events[name] = []
      } else {
        app.events = events = {}
      }
    },

    // eslint-disable-next-line
    emit(name, ...args) {
      ;(events[name] || []).map((listener) => {
        listener(...args)
      })
    },
  }

  return app
}

effects.js

/**
 * @copyright 2017-present, Charlike Mike Reagent <[email protected]>
 * @license Apache-2.0
 */
import assert from 'assert'
import { isObject } from './utils.js'

// effect signature: ({ state, actions }, a, b) => any
export default function createEffects (store, effects, reducers) {
  assert(isObject(store), 'expect `store` to be an object')
  assert(isObject(effects), 'expect `effects` to be an object')

  const context = { emit: store.emit }
  context.actions = Object.assign({}, reducers)

  Object.keys(effects).map((name) => {
    context.actions[name] = (a, b) => {
      store.emit('action', name, a, b)
      store.emit('effect', name, a, b)

      const effectPromise = new Promise((resolve) => {
        context.state = store.getState()
        resolve(effects[name](context, a, b))
      })

      return effectPromise.catch((er) => {
        store.emit('error', er)
      })
    }
  })

  return context.actions
}

reducers.js

/**
 * @copyright 2017-present, Charlike Mike Reagent <[email protected]>
 * @license Apache-2.0
 */
import assert from 'assert'
import { isObject } from './utils.js'

// reducer signature: ({ state }, a, b) => Object or Function returning an object
export default function createReducers (store, reducers) {
  assert(isObject(store), 'expect `store` to be an object')
  assert(isObject(reducers), 'expect `reducers` to be an object')

  return Object.keys(reducers).reduce((memo, name) => {
    memo[name] = (a, b) => {
      const context = { state: store.getState() }

      store.emit('action', name, a, b)
      store.emit('reducer', name, a, b)

      let next = null

      try {
        next = reducers[name](context, a, b)
      } catch (er) {
        store.emit('error', er)
        return null
      }

      return store.setState(next)
    }
    return memo
  }, {})
}

Weekly Digest (17 February, 2019 - 24 February, 2019)

Here's the Weekly Digest for tunnckoCoreLabs/elmaz:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please ๐Ÿ‘€ Watch and โญ Star the repository tunnckoCoreLabs/elmaz to receive next weekly updates. ๐Ÿ˜ƒ

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. ๐Ÿ“†

Weekly Digest (8 February, 2019 - 15 February, 2019)

Here's the Weekly Digest for tunnckoCoreLabs/elmaz:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please ๐Ÿ‘€ Watch and โญ Star the repository tunnckoCoreLabs/elmaz to receive next weekly updates. ๐Ÿ˜ƒ

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. ๐Ÿ“†

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.