{"id":13654371,"url":"https://github.com/icindy/WxNotificationCenter","last_synced_at":"2025-04-23T09:33:25.882Z","repository":{"id":75520557,"uuid":"72420788","full_name":"icindy/WxNotificationCenter","owner":"icindy","description":"WxNotificationCenter - 微信小程序通知广播模式类,降低小程序之间的耦合度","archived":false,"fork":false,"pushed_at":"2018-10-13T07:12:26.000Z","size":284,"stargazers_count":425,"open_issues_count":4,"forks_count":103,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-06T06:11:46.493Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/icindy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-10-31T09:15:44.000Z","updated_at":"2024-11-26T09:03:17.000Z","dependencies_parsed_at":"2023-06-06T17:45:46.411Z","dependency_job_id":null,"html_url":"https://github.com/icindy/WxNotificationCenter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icindy%2FWxNotificationCenter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icindy%2FWxNotificationCenter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icindy%2FWxNotificationCenter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icindy%2FWxNotificationCenter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icindy","download_url":"https://codeload.github.com/icindy/WxNotificationCenter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250407701,"owners_count":21425547,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T03:00:30.827Z","updated_at":"2025-04-23T09:33:25.544Z","avatar_url":"https://github.com/icindy.png","language":"JavaScript","funding_links":[],"categories":["实用库","Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# WxNotificationCenter\nWxNotificationCenter - 微信小程序通知广播模式类,降低小程序开发的耦合度\n\n## 信息\n\n来自[微信小程序开发论坛](http://weappdev.com/) [http://weappdev.com/](http://weappdev.com/)\n垂直微信小程序开发论坛\n\n## 版本信息\n\n`version 0.1`\n\n## 效果预览\n\n![WxNotificationCenter效果预览gif](screenshoot/wxnotice.gif)\n\n## 使用\n\n 1. copy 文件 `WxNotificationCenter.js` 到你的开发目录中\n\n 2. 引入 `WxNotificationCenter.js` 在你需要的`js`中\n\n  ```\n  var WxNotificationCenter = require(\"../../WxNotificationCenter/WxNotificationCenter.js\");\n  ```\n\n 3. 注册通知\n\n  ```\n  // 最好在onLoad中进行\n/**\n * addNotification\n * 注册通知对象方法\n * \n * 参数:\n * name： 注册名，一般let在公共类中\n * selector： 对应的通知方法，接受到通知后进行的动作\n * observer: 注册对象，指Page对象，可选，不填写的话在remove中会失效\n */\n\n  var that = this\n  WxNotificationCenter.addNotification(\"testNotificationName\",that.testNotificationFn,that)\n  ```\n\n 4. 发送通知\n\n  ```\n  WxNotificationCenter.postNotificationName(\"testNotificationName\");\n  ```\n\n 5. 移除通知\n\n  ```\n  // 移除通知在本也完成\n  WxNotificationCenter.removeNotification(\"testTabNotificationName\",that)\n  ```\n\n## 特性\n\n * 支持注册、发送、移除通知\n * 支持传参,字典等 \n\n## 源码分析\n\n * `var __notices = [];`\n\n \u003e 存放通知数组\n\n * `addNotification` 注册方法\n\n\t```\n\t * addNotification\n\t * 注册通知对象方法\n\t * \n\t * 参数:\n\t * name： 注册名，一般let在公共类中\n\t * selector： 对应的通知方法，接受到通知后进行的动作\n\t * observer: 注册对象，指Page对象\n\t */\n\n\t```\n\n * `postNotificationName` 发送方法\n\n   ```\n   /**\n\t * postNotificationName\n\t * 发送通知方法\n\t * \n\t * 参数:\n\t * name: 已经注册了的通知\n\t * info: 携带的参数\n\t */\n\n\tfunction postNotificationName(name, info)\n   ```\n\n * `removeNotification` 移除方法\n\n\t```\n\t/**\n\t * removeNotification\n\t * 移除通知方法\n\t * \n\t * 参数:\n\t * name: 已经注册了的通知\n\t * observer: 移除的通知所在的Page对象\n\t */\n\n\tfunction removeNotification(name,observer)\n\t```\n\n## 拓展阅读\n\n * 什么叫做通知广播模式\n \u003e 本类借鉴iOS开发中的NSNotificationCenter的消息模式进行开发\n\n 可阅读: [细说KVO \u0026 KVC \u0026 NSNotificationCenter那些事](http://www.jianshu.com/p/8f83f592a354)\n\n\n * 通知广播模式的使用场景\n \n  + 多级页面传值\n\n\n## 来源\n\n来自[微信小程序开发论坛](http://weappdev.com/) [http://weappdev.com/](http://weappdev.com/)\n垂直微信小程序开发论坛\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficindy%2FWxNotificationCenter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficindy%2FWxNotificationCenter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficindy%2FWxNotificationCenter/lists"}